#include #include "types1516.h" static const size_t cBufferSize = 100; // IEEE 1516.2, Section 4.12.9.1 void test1() { char* buffer = (char*)malloc(cBufferSize); memset(buffer, 0, cBufferSize); typedef #define FIELD_A 0 HLAfixedRecord > > TA; TA& A = (TA&)*buffer; A.field() = 'A'; A.field() = HLAtrue; A.field() = 3.14; std::stringstream result; result << A; const char* correct = "0000: 41 00 00 00 00 00 00 01 00 00 00 00 00 00 88 43\n"; if(strcmp(result.str().c_str(), correct) != 0) { std::cerr << "test1: does not match expected result" << std::endl << result.str() << std::endl << correct << std::endl; } else std::cout << result.str(); } // TODO: Add support for HLAvariantRecord // IEEE 1516.2, Section 4.12.9.3 void test3() { char* buffer = (char*)malloc(cBufferSize); memset(buffer, 0, cBufferSize); typedef #define FIELD_A 0 HLAfixedRecord > TA; typedef HLAfixedArray TB; TB& B = (TB&)*buffer; B[0].field() = '0'; B[1].field() = 42; B[1].field() = '1'; std::stringstream result; result << B; const char* correct = "0000: 00 00 00 00 30 00 00 00 00 00 00 2a 31\n"; if(strcmp(result.str().c_str(), correct) != 0) { std::cerr << "test2: does not match expected result" << std::endl << result.str() << std::endl << correct << std::endl; } else std::cout << result.str(); } // IEEE 1516.2, Section 4.12.9.4 void test4() { char* buffer = (char*)malloc(cBufferSize); memset(buffer, 0, cBufferSize); typedef HLAvariableArray TA; TA& A = (TA&)*buffer; A.size() = 1; A[0] = 3.14; std::stringstream result; result << A; const char* correct = "0000: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 88 43\n"; if(strcmp(result.str().c_str(), correct) != 0) { std::cerr << "test4: does not match expected result" << std::endl << result.str() << std::endl << correct << std::endl; } else std::cout << result.str(); } int main(int argc, char* argv[]) { test1(); test3(); test4(); return 0; }