|
| 1 | +// -- BEGIN LICENSE BLOCK ---------------------------------------------- |
| 2 | +// Copyright 2025 Universal Robots A/S |
| 3 | +// |
| 4 | +// Redistribution and use in source and binary forms, with or without |
| 5 | +// modification, are permitted provided that the following conditions are met: |
| 6 | +// |
| 7 | +// * Redistributions of source code must retain the above copyright |
| 8 | +// notice, this list of conditions and the following disclaimer. |
| 9 | +// |
| 10 | +// * Redistributions in binary form must reproduce the above copyright |
| 11 | +// notice, this list of conditions and the following disclaimer in the |
| 12 | +// documentation and/or other materials provided with the distribution. |
| 13 | +// |
| 14 | +// * Neither the name of the {copyright_holder} nor the names of its |
| 15 | +// contributors may be used to endorse or promote products derived from |
| 16 | +// this software without specific prior written permission. |
| 17 | +// |
| 18 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | +// POSSIBILITY OF SUCH DAMAGE. |
| 29 | +// -- END LICENSE BLOCK ------------------------------------------------ |
| 30 | + |
| 31 | +#include <gtest/gtest.h> |
| 32 | + |
| 33 | +#include <ur_client_library/primary/primary_client.h> |
| 34 | +#include <ur_client_library/ur/calibration_checker.h> |
| 35 | +#include <memory> |
| 36 | + |
| 37 | +using namespace urcl; |
| 38 | + |
| 39 | +std::string g_ROBOT_IP = "192.168.56.101"; |
| 40 | + |
| 41 | +class PrimaryClientTest : public ::testing::Test |
| 42 | +{ |
| 43 | +protected: |
| 44 | + void SetUp() override |
| 45 | + { |
| 46 | + client_ = std::make_unique<primary_interface::PrimaryClient>(g_ROBOT_IP, notifier_); |
| 47 | + } |
| 48 | + |
| 49 | + std::unique_ptr<primary_interface::PrimaryClient> client_; |
| 50 | + comm::INotifier notifier_; |
| 51 | +}; |
| 52 | + |
| 53 | +TEST_F(PrimaryClientTest, start_communication_succeeds) |
| 54 | +{ |
| 55 | + EXPECT_NO_THROW(client_->start()); |
| 56 | +} |
| 57 | + |
| 58 | +TEST_F(PrimaryClientTest, add_and_remove_consumer) |
| 59 | +{ |
| 60 | + auto calibration_consumer = std::make_shared<urcl::CalibrationChecker>("test"); |
| 61 | + |
| 62 | + client_->addPrimaryConsumer(calibration_consumer); |
| 63 | + |
| 64 | + EXPECT_NO_THROW(client_->start()); |
| 65 | + |
| 66 | + auto start_time = std::chrono::system_clock::now(); |
| 67 | + const auto timeout = std::chrono::seconds(5); |
| 68 | + while (!calibration_consumer->isChecked() && std::chrono::system_clock::now() - start_time < timeout) |
| 69 | + { |
| 70 | + std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 71 | + } |
| 72 | + EXPECT_TRUE(calibration_consumer->isChecked()); |
| 73 | + |
| 74 | + client_->removePrimaryConsumer(calibration_consumer); |
| 75 | +} |
| 76 | + |
| 77 | +int main(int argc, char* argv[]) |
| 78 | +{ |
| 79 | + ::testing::InitGoogleTest(&argc, argv); |
| 80 | + |
| 81 | + return RUN_ALL_TESTS(); |
| 82 | +} |
0 commit comments