int main() { print_assert_exception([]{ TEST_FAIL("Good"); }); TEST_ASSERT_TRUE(true); TEST_ASSERT_TRUE_MSG(true, "Bad"); std::string a("Hello world"); std::string b("Hello, world"); print_assert_exception([&]{ TEST_ASSERT_TRUE(a == b); }); print_assert_exception([&]{ TEST_ASSERT_TRUE_MSG(a == b, "Good"); }); TEST_ASSERT_FALSE(false); TEST_ASSERT_FALSE_MSG(false, "Bad"); print_assert_exception([&]{ TEST_ASSERT_FALSE(a != b); }); print_assert_exception([&]{ TEST_ASSERT_FALSE_MSG(a != b, "Good"); }); TEST_ASSERT_EQUALS(std::string, a, "Hello world"); TEST_ASSERT_EQUALS_MSG(std::string, a, "Hello world", "Bad"); print_assert_exception([&]{ TEST_ASSERT_EQUALS(std::string, a, b); }); print_assert_exception([&]{ TEST_ASSERT_EQUALS_MSG(std::string, a, b, "Good"); }); return EXIT_SUCCESS; }
// ---------------------------------------------------------------------------- void DispatcherTest::testActionRetransmissionWithAbort() { component1->callAction(10, 0xf3); dispatcher->update(); for (uint8_t i = 0; i < 3; i++) { TEST_ASSERT_EQUALS(backend->messagesSend.getSize(), 1U); TEST_ASSERT_EQUALS(backend->messagesSend.getFront().payload.getSize(), 0U); TEST_ASSERT_EQUALS(backend->messagesSend.getFront().header, xpcc::Header(xpcc::Header::REQUEST, false, 10, 1, 0xf3)); backend->messagesSend.removeAll(); // reset time so that the timeout is expired TestingClock::time += 100; dispatcher->update(); } // transmission should be aborted by now TEST_ASSERT_EQUALS(backend->messagesSend.getSize(), 0U); }
void BoundedDequeTest::testConstIterator() { xpcc::BoundedDeque<int16_t, 5> deque; deque.append(3); deque.append(4); deque.prepend(2); deque.prepend(1); xpcc::BoundedDeque<int16_t, 5>::const_iterator it; it = deque.begin(); TEST_ASSERT_TRUE(it != deque.end()); TEST_ASSERT_EQUALS(*it, 1); ++it; TEST_ASSERT_TRUE(it != deque.end()); TEST_ASSERT_EQUALS(*it, 2); ++it; TEST_ASSERT_TRUE(it != deque.end()); TEST_ASSERT_EQUALS(*it, 3); ++it; TEST_ASSERT_TRUE(it != deque.end()); TEST_ASSERT_EQUALS(*it, 4); ++it; TEST_ASSERT_FALSE(it != deque.end()); }
void BoundedDequeTest::testBackward() { xpcc::BoundedDeque<int16_t, 3> deque; TEST_ASSERT_TRUE(deque.prepend(1)); TEST_ASSERT_TRUE(deque.prepend(2)); TEST_ASSERT_TRUE(deque.prepend(3)); TEST_ASSERT_FALSE(deque.prepend(4)); TEST_ASSERT_TRUE(deque.isFull()); TEST_ASSERT_EQUALS(deque.getBack(), 1); deque.removeBack(); TEST_ASSERT_EQUALS(deque.getBack(), 2); deque.removeBack(); TEST_ASSERT_TRUE(deque.prepend(4)); TEST_ASSERT_TRUE(deque.prepend(5)); TEST_ASSERT_TRUE(deque.isFull()); TEST_ASSERT_EQUALS(deque.getBack(), 3); deque.removeBack(); TEST_ASSERT_EQUALS(deque.getBack(), 4); deque.removeBack(); TEST_ASSERT_EQUALS(deque.getBack(), 5); deque.removeBack(); TEST_ASSERT_TRUE(deque.isEmpty()); }
void DispatcherTest::testInternalActionCallDirectResponse() { xpcc::ResponseCallback callback(component2, &TestingComponent2::responseNoParameter); component2->callAction(1, 0x12, callback); dispatcher->update(); dispatcher->update(); TEST_ASSERT_EQUALS(timeline->events.getSize(), 2U); TEST_ASSERT_TRUE(timeline->events.getFront().type == Timeline::ACTION); TEST_ASSERT_EQUALS(timeline->events.getFront().id, 0x12); TEST_ASSERT_EQUALS(timeline->events.getFront().component, 1); TEST_ASSERT_EQUALS(timeline->events.getFront().source, 2); TEST_ASSERT_EQUALS(timeline->events.getFront().payload.getSize(), 0U); timeline->events.removeFront(); TEST_ASSERT_TRUE(timeline->events.getFront().type == Timeline::RESPONSE); TEST_ASSERT_EQUALS(timeline->events.getFront().id, 0x30); TEST_ASSERT_EQUALS(timeline->events.getFront().component, 2); TEST_ASSERT_EQUALS(timeline->events.getFront().source, 1); TEST_ASSERT_EQUALS(timeline->events.getFront().payload.getSize(), 0U); // TODO should it be possible to disable this behavior TEST_ASSERT_EQUALS(backend->messagesSend.getSize(), 2U); }
void DynamicArrayTest::testClear() { xpcc::DynamicArray<unittest::CountType> array(5); TEST_ASSERT_EQUALS(unittest::CountType::numberOfDefaultConstructorCalls, 0U); TEST_ASSERT_EQUALS(unittest::CountType::numberOfOperations, 0U); unittest::CountType::reset(); unittest::CountType data; TEST_ASSERT_EQUALS(unittest::CountType::numberOfDefaultConstructorCalls, 1U); TEST_ASSERT_EQUALS(unittest::CountType::numberOfOperations, 1U); unittest::CountType::reset(); array.append(data); array.append(data); array.append(data); TEST_ASSERT_EQUALS(unittest::CountType::numberOfCopyConstructorCalls, 3U); TEST_ASSERT_EQUALS(unittest::CountType::numberOfOperations, 3U); array.clear(); TEST_ASSERT_EQUALS(unittest::CountType::numberOfDestructorCalls, 3U); TEST_ASSERT_EQUALS(unittest::CountType::numberOfOperations, 6U); TEST_ASSERT_EQUALS(array.getSize(), 0U); TEST_ASSERT_EQUALS(array.getCapacity(), 0U); }
void BlockAllocatorTest::testAllocate() { uint8_t *heap = new uint8_t[512]; xpcc::BlockAllocator<uint16_t, 8> allocator; allocator.initialize(heap, heap + 512); TEST_ASSERT_EQUALS(allocator.getAvailableSize(), 496U); allocator.allocate(12); TEST_ASSERT_EQUALS(allocator.getAvailableSize(), 480U); allocator.allocate(13); TEST_ASSERT_EQUALS(allocator.getAvailableSize(), 448U); allocator.allocate(440); TEST_ASSERT_EQUALS(allocator.getAvailableSize(), 0U); TEST_ASSERT_EQUALS(allocator.allocate(1), (void *) 0); delete[] heap; }
void TimeoutTest::testDefaultConstructor() { xpcc::GenericTimeout<xpcc::ClockDummy, xpcc::ShortTimestamp> timeoutShort; xpcc::GenericTimeout<xpcc::ClockDummy, xpcc::Timestamp> timeout; TEST_ASSERT_EQUALS(timeoutShort.remaining(), 0l); TEST_ASSERT_EQUALS(timeout.remaining(), 0l); TEST_ASSERT_TRUE(timeoutShort.isStopped()); TEST_ASSERT_TRUE(timeout.isStopped()); TEST_ASSERT_FALSE(timeoutShort.isArmed()); TEST_ASSERT_FALSE(timeout.isArmed()); TEST_ASSERT_FALSE(timeoutShort.isExpired()); TEST_ASSERT_FALSE(timeout.isExpired()); TEST_ASSERT_FALSE(timeoutShort.execute()); TEST_ASSERT_FALSE(timeout.execute()); TEST_ASSERT_FALSE(timeoutShort.isExpired()); TEST_ASSERT_FALSE(timeout.isExpired()); TEST_ASSERT_EQUALS(timeoutShort.remaining(), 0l); TEST_ASSERT_EQUALS(timeout.remaining(), 0l); }
void TimeoutTest::testTimeOverflow() { xpcc::ShortTimestamp::Type time = xpcc::ArithmeticTraits<xpcc::ShortTimestamp::Type>::max; TEST_ASSERT_EQUALS(time, 65535); // overflow after 65535 for uint16_t => 32767+100 = 32867 xpcc::ClockDummy::setTime(time / 2 + 100); TEST_ASSERT_EQUALS((time / 2 + 100), 32867); xpcc::GenericTimeout<xpcc::ClockDummy, xpcc::ShortTimestamp> timeoutShort(time / 2 - 1); //=> 32867 + 32766 = 97 TEST_ASSERT_EQUALS((time / 2 - 1), 32766); TEST_ASSERT_FALSE(timeoutShort.execute()); xpcc::ClockDummy::setTime(time); TEST_ASSERT_FALSE(timeoutShort.execute()); xpcc::ClockDummy::setTime(0); TEST_ASSERT_FALSE(timeoutShort.execute()); // Overflow happened. This needs to be avoided by the user! xpcc::ClockDummy::setTime(100); TEST_ASSERT_TRUE(timeoutShort.execute()); }
void Circle2DTest::testDefaultConstructor() { xpcc::Circle2D<int16_t> circle; TEST_ASSERT_EQUALS(circle.getRadius(), 0); TEST_ASSERT_EQUALS(circle.getCenter(), xpcc::Vector2i(0, 0)); }
void SimpleListTest::testSwap() { SimpleList v1(2, (void*)"a"); TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(m_list)); TEST_ASSERT_EQUALS("{a, a}", c_str(v1)); m_list.swap(v1); TEST_ASSERT_EQUALS("{a, a}", c_str(m_list)); TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(v1)); }
void DynamicArrayTest::testConstIteratorAccess() { xpcc::DynamicArray<IteratorTestClass> list(2); list.append(IteratorTestClass(12, -1532)); xpcc::DynamicArray<IteratorTestClass>::const_iterator it = list.begin(); TEST_ASSERT_EQUALS(it->a, 12); TEST_ASSERT_EQUALS(it->b, -1532); }
void DynamicArrayTest::testSequenceConstructor() { Container array(10, 123); TEST_ASSERT_FALSE(array.isEmpty()); TEST_ASSERT_EQUALS(array.getSize(), 10U); for (uint_fast16_t i = 0; i < array.getSize(); ++i) { TEST_ASSERT_EQUALS(array[i], 123); } }
void SimpleListTest::testStackOperation() { TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(m_list)); m_list.push_front((void*)"a"); TEST_ASSERT_EQUALS("{a, 1st, 2nd, 3rd, 4th, 5th}", c_str(m_list)); m_list.pop_front(); TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(m_list)); m_list.push_back((void*)"a"); TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th, a}", c_str(m_list)); m_list.pop_back(); TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(m_list)); }
void DispatcherTest::testReceiveResponseNoComponent() { Message message(xpcc::Header(xpcc::Header::RESPONSE, false, 11, 10, 0x10), xpcc::SmartPointer()); backend->messagesToReceive.append(message); dispatcher->update(); TEST_ASSERT_EQUALS(postman->messagesToDeliver.getSize(), 0U); TEST_ASSERT_EQUALS(backend->messagesSend.getSize(), 0U); }
void TestUtility::testNetworkInfo() { TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_LOOPBACK, Utility::getNetworkType("127.0.0.1")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_LOOPBACK, Utility::getNetworkType("::1")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_LOCAL_NETWORK, Utility::getNetworkType("10.11.12.13")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_LOCAL_NETWORK, Utility::getNetworkType("172.24.25.26")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_LOCAL_NETWORK, Utility::getNetworkType("192.168.2.13")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_LOCAL_NETWORK, Utility::getNetworkType("fd00::d250:99ff:fe5e:4907")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_INTERNET, Utility::getNetworkType("81.81.81.81")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_INTERNET, Utility::getNetworkType("7.7.7.7")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_INTERNET, Utility::getNetworkType("2002:ADC2:712F:0:0:0:0:0")); TEST_ASSERT_EQUALS(Utility::AddressType::ADDRESS_INTERNET, Utility::getNetworkType("::ADC2:712F")); }
void DispatcherTest::testEventTransmission() { uint32_t payload = 0x12345678; component2->publishEvent(0x21, payload); dispatcher->update(); // Event was delivered to the internal component TEST_ASSERT_EQUALS(timeline->events.getSize(), 1U); TEST_ASSERT_TRUE(timeline->events.getFront().type == Timeline::EVENT); TEST_ASSERT_EQUALS(timeline->events.getFront().id, 0x21); TEST_ASSERT_EQUALS(timeline->events.getFront().source, 2); TEST_ASSERT_EQUALS(timeline->events.getFront().payload.getSize(), 4); // Event was also send to the backend (broadcast) TEST_ASSERT_EQUALS(backend->messagesSend.getSize(), 1U); TEST_ASSERT_EQUALS(backend->messagesSend.getFront().payload.getSize(), 4U); TEST_ASSERT_EQUALS( backend->messagesSend.getFront().payload.get<uint32_t>(), 0x12345678U); xpcc::Header header(xpcc::Header::REQUEST, false, 0, 2, 0x21); TEST_ASSERT_EQUALS(backend->messagesSend.getFront().header, header); }
// ---------------------------------------------------------------------------- void Ad7280aTest::testCrcMessage() { // Datasheet Example 1 TEST_ASSERT_EQUALS(Ad7280a::calculateCrc(0x003430), 0x51); // Datasheet Example 2 TEST_ASSERT_EQUALS(Ad7280a::calculateCrc(0x103430), 0x74); // Datasheet Example 3 TEST_ASSERT_EQUALS(Ad7280a::calculateCrc(0x0070A1), 0x9A); // Datasheet Example 4 TEST_ASSERT_EQUALS(Ad7280a::calculateCrc(0x205335), 0x46); }
void PointSet2DTest::testConstructor() { xpcc::PointSet2D<int16_t> set(5); TEST_ASSERT_EQUALS(set.getNumberOfPoints(), 0U); }
void DispatcherTest::testReceiveRequestNoComponent() { Message message(xpcc::Header(xpcc::Header::REQUEST, false, 11, 10, 0x10), xpcc::SmartPointer()); backend->messagesToReceive.append(message); dispatcher->update(); // message was delivered TEST_ASSERT_EQUALS(postman->messagesToDeliver.getSize(), 1U); TEST_ASSERT_TRUE(postman->messagesToDeliver.getFront() == message); TEST_ASSERT_EQUALS(backend->messagesSend.getSize(), 0U); }
void RegisterTest::testCasting() { Test_t v1 = static_cast<Test>(0xff); TEST_ASSERT_EQUALS(v1.value, 0xff); v1 = Test(0xee); TEST_ASSERT_EQUALS(v1.value, 0xee); v1 = Test_t(0xdd); TEST_ASSERT_EQUALS(v1.value, 0xdd); Test_t v2(0xff); TEST_ASSERT_EQUALS(v2.value, 0xff); Common_t c1 = Common_t(0xff); TEST_ASSERT_EQUALS(c1.value, 0xff); }
// ---------------------------------------------------------------------------- void DispatcherTest::testEventReception() { Message message(xpcc::Header(xpcc::Header::REQUEST, false, 0, 10, 0x20), xpcc::SmartPointer()); backend->messagesToReceive.append(message); dispatcher->update(); // message was delivered TEST_ASSERT_EQUALS(postman->messagesToDeliver.getSize(), 1U); TEST_ASSERT_TRUE(postman->messagesToDeliver.getFront() == message); TEST_ASSERT_EQUALS(timeline->events.getSize(), 2U); }
void Circle2DTest::testConstructor() { xpcc::Circle2D<int16_t> circle( xpcc::Vector2i(-10, -20), 45); TEST_ASSERT_EQUALS(circle.getRadius(), 45); TEST_ASSERT_EQUALS(circle.getCenter(), xpcc::Vector2i(-10, -20)); circle.setCenter(xpcc::Vector2i(20, 30)); circle.setRadius(70); TEST_ASSERT_EQUALS(circle.getRadius(), 70); TEST_ASSERT_EQUALS(circle.getCenter(), xpcc::Vector2i(20, 30)); }
void Circle2DTest::testIntersectionCircle() { xpcc::Circle2D<int16_t> circle1( xpcc::Vector2i(), 10); xpcc::Circle2D<int16_t> circle2( xpcc::Vector2i(30, 0), 20); xpcc::PointSet2D<int16_t> points; // circle touch each other with one point TEST_ASSERT_TRUE(circle1.getIntersections(circle2, points)); TEST_ASSERT_EQUALS(points.getNumberOfPoints(), 1U); TEST_ASSERT_EQUALS(points[0].getX(), 10); TEST_ASSERT_EQUALS(points[0].getY(), 0); points.removeAll(); // no intersection circle2.setRadius(10); TEST_ASSERT_FALSE(circle1.getIntersections(circle2, points)); TEST_ASSERT_EQUALS(points.getNumberOfPoints(), 0U); // 2 intersection points (15, -25.98) and (15, 25.98) circle1.setRadius(30); circle2.setRadius(30); TEST_ASSERT_TRUE(circle1.getIntersections(circle2, points)); TEST_ASSERT_EQUALS(points.getNumberOfPoints(), 2U); TEST_ASSERT_EQUALS(points[0].getX(), 15); TEST_ASSERT_EQUALS(points[0].getY(), -26); TEST_ASSERT_EQUALS(points[1].getX(), 15); TEST_ASSERT_EQUALS(points[1].getY(), 26); points.removeAll(); // circle 1 is contained inside circle 2 circle1.setRadius(10); circle2.setCenter(xpcc::Vector2i(0, 0)); TEST_ASSERT_FALSE(circle1.getIntersections(circle2, points)); TEST_ASSERT_EQUALS(points.getNumberOfPoints(), 0U); }
void PointSet2DTest::testIterator() { xpcc::PointSet2D<int16_t> set(3); set.append(xpcc::Vector2i(10, 20)); set.append(xpcc::Vector2i(20, 30)); set.append(xpcc::Vector2i(30, 40)); xpcc::PointSet2D<int16_t>::const_iterator it; int count; for (it = set.begin(), count = 0; it != set.end(); ++it, ++count) { TEST_ASSERT_EQUALS(set[count], (*it)); } TEST_ASSERT_EQUALS(count, 3); }
void DynamicArrayTest::testDefaultConstrutor() { Container array; TEST_ASSERT_TRUE(array.isEmpty()); TEST_ASSERT_EQUALS(array.getSize(), 0U); }
void DynamicArrayTest::testIteratorAccess() { xpcc::DynamicArray<IteratorTestClass> list(2); list.append(IteratorTestClass(12, -1532)); xpcc::DynamicArray<IteratorTestClass>::iterator it = list.begin(); TEST_ASSERT_EQUALS(it->a, 12); TEST_ASSERT_EQUALS(it->b, -1532); it->a = 66; TEST_ASSERT_EQUALS(it->a, 66); (*it).b = 22312; TEST_ASSERT_EQUALS(it->b, 22312); }
void SimpleListTest::testListOperation() { TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(m_list)); // insert(iterator, value_type) m_list.insert(++m_list.begin(), (void*)"a"); TEST_ASSERT_EQUALS("{1st, a, 2nd, 3rd, 4th, 5th}", c_str(m_list)); // erase(iterator) m_list.erase(++m_list.begin()); TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(m_list)); // insert(iterator, size_type, value_type) m_list.insert(++m_list.begin(), 2, (void*)"a"); TEST_ASSERT_EQUALS("{1st, a, a, 2nd, 3rd, 4th, 5th}", c_str(m_list)); // erase(iterator, iterator) m_list.erase(++m_list.begin(), ++(++(++m_list.begin()))); TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(m_list)); const char* ab[] = { "a", "b" }; // insert(iterator, const_pointer, const_pointer) m_list.insert(++m_list.begin(), (void**)ab, (void**)ab + 2); TEST_ASSERT_EQUALS("{1st, a, b, 2nd, 3rd, 4th, 5th}", c_str(m_list)); SimpleList tmp((void**)ab, (void**)ab + 2); // insert(iterator, const_iterator, const_iterator) m_list.insert(--m_list.end(), tmp.begin(), tmp.end()); TEST_ASSERT_EQUALS("{1st, a, b, 2nd, 3rd, 4th, a, b, 5th}", c_str(m_list)); }
void DynamicArrayTest::testAllocationConstructor() { Container array(10); TEST_ASSERT_TRUE(array.isEmpty()); TEST_ASSERT_EQUALS(array.getSize(), 0U); TEST_ASSERT_TRUE(array.getCapacity() >= 10); }
void DynamicArrayTest::testRemove() { Container array(2, 5); TEST_ASSERT_FALSE(array.isEmpty()); TEST_ASSERT_EQUALS(array.getSize(), 2U); array.removeBack(); TEST_ASSERT_FALSE(array.isEmpty()); TEST_ASSERT_EQUALS(array.getSize(), 1U); array.removeBack(); TEST_ASSERT_TRUE(array.isEmpty()); TEST_ASSERT_EQUALS(array.getSize(), 0U); }