Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UAVCAN UAVCAN_Subscriber
dsdl_test.cpp
00001 /* 00002 * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com> 00003 */ 00004 00005 #if __GNUC__ 00006 # pragma GCC diagnostic ignored "-Wfloat-equal" 00007 #endif 00008 00009 #include <gtest/gtest.h> 00010 #include <uavcan/transport/transfer_buffer.hpp> 00011 #include <limits> 00012 #include <root_ns_a/EmptyService.hpp> 00013 #include <root_ns_a/EmptyMessage.hpp> 00014 #include <root_ns_a/NestedMessage.hpp> 00015 #include <root_ns_a/A.hpp> 00016 #include <root_ns_a/ReportBackSoldier.hpp> 00017 #include <root_ns_b/ServiceWithEmptyRequest.hpp> 00018 #include <root_ns_b/ServiceWithEmptyResponse.hpp> 00019 #include <root_ns_b/T.hpp> 00020 00021 00022 TEST(Dsdl, EmptyServices) 00023 { 00024 uavcan::StaticTransferBuffer<100> buf; 00025 uavcan::BitStream bs_wr(buf); 00026 uavcan::ScalarCodec sc_wr(bs_wr); 00027 00028 root_ns_b::ServiceWithEmptyRequest::Request req; 00029 ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Request::encode(req, sc_wr)); 00030 ASSERT_EQ("", bs_wr.toString()); 00031 00032 root_ns_b::ServiceWithEmptyRequest::Response resp; 00033 ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Response::encode(resp, sc_wr)); 00034 ASSERT_EQ("", bs_wr.toString()); 00035 00036 resp.covariance.push_back(-2); 00037 resp.covariance.push_back(65504); 00038 root_ns_b::ServiceWithEmptyRequest::Response::encode(resp, sc_wr); 00039 ASSERT_EQ("00000000 11000000 11111111 01111011", bs_wr.toString()); 00040 00041 resp.covariance.push_back(42); 00042 resp.covariance[0] = 999; 00043 00044 uavcan::BitStream bs_rd(buf); 00045 uavcan::ScalarCodec sc_rd(bs_rd); 00046 ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Response::decode(resp, sc_rd)); 00047 00048 ASSERT_EQ(2, resp.covariance.size()); 00049 ASSERT_EQ(-2, resp.covariance[0]); 00050 ASSERT_EQ(65504, resp.covariance[1]); 00051 } 00052 00053 00054 TEST(Dsdl, Signature) 00055 { 00056 ASSERT_EQ(0xe74617107a34aa9c, root_ns_a::EmptyService::getDataTypeSignature().get()); 00057 ASSERT_STREQ("root_ns_a.EmptyService", root_ns_a::EmptyService::getDataTypeFullName()); 00058 ASSERT_EQ(uavcan::DataTypeKindService, root_ns_a::EmptyService::DataTypeKind); 00059 00060 ASSERT_EQ(0x99604d7066e0d713, root_ns_a::NestedMessage::getDataTypeSignature().get()); // Computed manually 00061 ASSERT_STREQ("root_ns_a.NestedMessage", root_ns_a::NestedMessage::getDataTypeFullName()); 00062 ASSERT_EQ(uavcan::DataTypeKindMessage, root_ns_a::NestedMessage::DataTypeKind); 00063 } 00064 00065 00066 TEST(Dsdl, Operators) 00067 { 00068 { 00069 root_ns_a::EmptyService::Request a, b; 00070 ASSERT_TRUE(a == b); 00071 ASSERT_FALSE(a != b); 00072 } 00073 { 00074 root_ns_a::NestedMessage c, d; 00075 ASSERT_TRUE(c == d); 00076 ASSERT_FALSE(c != d); 00077 00078 c.field = 1; 00079 ASSERT_FALSE(c == d); 00080 ASSERT_TRUE(c != d); 00081 } 00082 } 00083 00084 00085 TEST(Dsdl, CloseComparison) 00086 { 00087 root_ns_a::A first, second; 00088 00089 ASSERT_TRUE(first == second); 00090 00091 first.vector[1].vector[1] = std::numeric_limits<double>::epsilon(); 00092 ASSERT_TRUE(first.isClose(second)); // Still close 00093 ASSERT_FALSE(first == second); // But not exactly 00094 00095 first.vector[1].vector[1] = std::numeric_limits<float>::epsilon(); 00096 ASSERT_FALSE(first.isClose(second)); // Nope 00097 ASSERT_FALSE(first == second); // Ditto 00098 } 00099 00100 /* 00101 * This test assumes that it will be executed before other GDTR tests; otherwise it fails. 00102 * TODO: Probably it needs to be called directly from main() 00103 */ 00104 //TEST(Dsdl, Registration) 00105 //{ 00106 // using uavcan::GlobalDataTypeRegistry; 00107 // /* 00108 // * Descriptors 00109 // */ 00110 // const uavcan::DataTypeDescriptor* desc = UAVCAN_NULLPTR; 00111 // 00112 // desc = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, "root_ns_a.EmptyMessage"); 00113 // ASSERT_TRUE(desc); 00114 // ASSERT_EQ(root_ns_a::EmptyMessage::DefaultDataTypeID, desc->getID()); 00115 // ASSERT_EQ(root_ns_a::EmptyMessage::DataTypeKind, desc->getKind()); 00116 // ASSERT_EQ(root_ns_a::EmptyMessage::getDataTypeSignature(), desc->getSignature()); 00117 // ASSERT_STREQ(root_ns_a::EmptyMessage::getDataTypeFullName(), desc->getFullName()); 00118 // 00119 // desc = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindService, "root_ns_a.EmptyService"); 00120 // ASSERT_TRUE(desc); 00121 // ASSERT_EQ(root_ns_a::EmptyService::DefaultDataTypeID, desc->getID()); 00122 // ASSERT_EQ(root_ns_a::EmptyService::DataTypeKind, desc->getKind()); 00123 // ASSERT_EQ(root_ns_a::EmptyService::getDataTypeSignature(), desc->getSignature()); 00124 // ASSERT_STREQ(root_ns_a::EmptyService::getDataTypeFullName(), desc->getFullName()); 00125 // 00126 // desc = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindService, "root_ns_a.ReportBackSoldier"); 00127 // ASSERT_TRUE(desc); 00128 // ASSERT_EQ(root_ns_a::ReportBackSoldier::DefaultDataTypeID, desc->getID()); 00129 // ASSERT_EQ(root_ns_a::ReportBackSoldier::DataTypeKind, desc->getKind()); 00130 // ASSERT_EQ(root_ns_a::ReportBackSoldier::getDataTypeSignature(), desc->getSignature()); 00131 // ASSERT_STREQ(root_ns_a::ReportBackSoldier::getDataTypeFullName(), desc->getFullName()); 00132 // 00133 // /* 00134 // * Mask 00135 // */ 00136 // uavcan::DataTypeIDMask mask; 00137 // 00138 // GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, mask); 00139 // ASSERT_TRUE(mask[8]); 00140 // mask[8] = false; 00141 // 00142 // GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindService, mask); 00143 // ASSERT_TRUE(mask[1]); 00144 // ASSERT_TRUE(mask[3]); 00145 // mask[1] = mask[3] = false; 00146 // 00147 // /* 00148 // * Reset 00149 // */ 00150 // GlobalDataTypeRegistry::instance().reset(); 00151 // ASSERT_FALSE(GlobalDataTypeRegistry::instance().isFrozen()); 00152 //}
Generated on Tue Jul 12 2022 17:17:31 by
1.7.2