certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi/libHLA CMakeLists.txt TestHLAtypes.cc


From: certi-cvs
Subject: [certi-cvs] certi/libHLA CMakeLists.txt TestHLAtypes.cc
Date: Thu, 06 Nov 2008 16:18:38 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Petr Gotthard <gotthardp>       08/11/06 16:18:38

Modified files:
        libHLA         : CMakeLists.txt 
Added files:
        libHLA         : TestHLAtypes.cc 

Log message:
        First module tests added.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libHLA/CMakeLists.txt?cvsroot=certi&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/certi/libHLA/TestHLAtypes.cc?cvsroot=certi&rev=1.1

Patches:
Index: CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libHLA/CMakeLists.txt,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CMakeLists.txt      2 Aug 2008 14:03:14 -0000       1.3
+++ CMakeLists.txt      6 Nov 2008 16:18:38 -0000       1.4
@@ -23,6 +23,16 @@
                         
 SET_TARGET_PROPERTIES(HLA PROPERTIES VERSION 1.0.0 SOVERSION 1)
 
+SET(TestHLAtypes_SRCS
+  TestHLAtypes.cc
+)
+
+ADD_EXECUTABLE(TestHLAtypes ${TestHLAtypes_SRCS})
+
+TARGET_LINK_LIBRARIES(TestHLAtypes HLA)
+
+ADD_TEST(HLAtypes TestHLAtypes)
+
 INSTALL(FILES
     HLAtypesIEEE1516.hh
     HLAbuffer.hh

Index: TestHLAtypes.cc
===================================================================
RCS file: TestHLAtypes.cc
diff -N TestHLAtypes.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ TestHLAtypes.cc     6 Nov 2008 16:18:38 -0000       1.1
@@ -0,0 +1,197 @@
+// ----------------------------------------------------------------------------
+// TestHLAtypes.cc - Module test for the IEEE 1516.2 compliant datatypes
+// Copyright (C) 2008  Petr Gotthard <address@hidden>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1, as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// $Id: TestHLAtypes.cc,v 1.1 2008/11/06 16:18:38 gotthardp Exp $
+// ----------------------------------------------------------------------------
+
+#include <memory>
+#include <sstream>
+
+#include <HLAtypesIEEE1516.hh>
+
+using namespace libhla;
+
+// IEEE 1516.2, Section 4.12.9.1
+int test1()
+{
+    typedef
+      HLAfixedRecord<
+#define FIELD_A 0
+        HLAfixedField<FIELD_A, HLAoctet,
+#define FIELD_B 1
+        HLAfixedField<FIELD_B, HLAboolean,
+#define FIELD_C 2
+        HLAfixedField<FIELD_C, HLAfloat64BE
+        > > > > TA;
+
+    HLAdata<TA> A;
+    (*A).field<FIELD_A>() = 'A';
+    (*A).field<FIELD_B>() = HLAtrue;
+    (*A).field<FIELD_C>() = 3.14;
+
+    std::stringstream result;
+    A.print(result);
+
+    const char* correct =
+        "0000:  41 00 00 00 00 00 00 01 40 09 1e b8 51 eb 85 1f\n";
+
+    if(strcmp(result.str().c_str(), correct) != 0) {
+        std::cerr << "test1: <output> does not match expected result" << 
std::endl
+            << result.str() << std::endl << correct << std::endl;
+        return 1;
+    }
+    else {
+        std::cout << result.str();
+        return 0;
+    }
+}
+
+// TODO: Add support for HLAvariantRecord
+
+// IEEE 1516.2, Section 4.12.9.3
+int test3()
+{
+    typedef
+      HLAfixedRecord<
+#define FIELD_A 0
+        HLAfixedField<FIELD_A, HLAinteger32BE,
+#define FIELD_B 1
+        HLAfixedField<FIELD_B, HLAoctet
+        > > > TA;
+
+    typedef HLAfixedArray<TA,2> TB;
+
+    HLAdata<TB> B;
+    (*B)[0].field<FIELD_B>() = '0';
+    (*B)[1].field<FIELD_A>() = 42;
+    (*B)[1].field<FIELD_B>() = '1';
+
+    std::stringstream result;
+    B.print(result);
+
+    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: <output> does not match expected result" << 
std::endl
+            << result.str() << std::endl << correct << std::endl;
+        return 1;
+    }
+    else {
+        std::cout << result.str();
+        return 0;
+    }
+}
+
+// IEEE 1516.2, Section 4.12.9.4
+int test4()
+{
+    typedef HLAvariableArray<HLAfloat64BE> TA;
+
+    HLAdata<TA> A;
+    (*A).set_size(1);
+    (*A)[0] = 3.14;
+
+    std::stringstream result;
+    A.print(result);
+
+    const char* correct =
+        "0000:  00 00 00 01 00 00 00 00 40 09 1e b8 51 eb 85 1f\n";
+
+    if(strcmp(result.str().c_str(), correct) != 0) {
+        std::cerr << "test4: <output> does not match expected result" << 
std::endl
+            << result.str() << std::endl << correct << std::endl;
+        return 1;
+    }
+    else {
+        std::cout << result.str();
+        return 0;
+    }
+}
+
+int test5()
+{
+    typedef
+      HLAvariableArray<
+        HLAfixedRecord<
+#define FIELD_A 0
+          HLAfixedField<FIELD_A, HLAvariableArray<HLAfloat64LE>,
+#define FIELD_B 1
+          HLAfixedField<FIELD_B, HLAvariableArray<HLAinteger32LE>
+          > > > > TA;
+
+    HLAdata<TA> A;
+    (*A).set_size(1);
+    (*A)[0].field<FIELD_A>().set_size(1);
+    (*A)[0].field<FIELD_A>()[0] = 3.14;
+    (*A)[0].field<FIELD_B>().set_size(1);
+    (*A)[0].field<FIELD_B>()[0] = 7;
+
+    (*A)[0].field<FIELD_A>().set_size(2);
+    (*A)[0].field<FIELD_A>()[1] = 2.718;
+
+    std::stringstream result;
+    A.print(result);
+
+    const char* correct =
+        "0000:  00 00 00 01 00 00 00 00 00 00 00 02 00 00 00 00\n"
+        "0010:  1f 85 eb 51 b8 1e 09 40 58 39 b4 c8 76 be 05 40\n"
+        "0020:  00 00 00 01 07 00 00 00\n";
+
+    if(strcmp(result.str().c_str(), correct) != 0) {
+        std::cerr << "test1: <output> does not match expected result" << 
std::endl
+            << result.str() << std::endl << correct << std::endl;
+        return 1;
+    }
+    else {
+        std::cout << result.str();
+        return 0;
+    }
+}
+
+int test6()
+{
+    HLAdata<HLAASCIIstring> A;
+    *A = "UFO";
+
+    std::stringstream result;
+    A.print(result);
+
+    const char* correct =
+        "0000:  00 00 00 03 55 46 4f\n";
+
+    if(strcmp(result.str().c_str(), correct) != 0) {
+        std::cerr << "test6: <output> does not match expected result" << 
std::endl
+            << result.str() << std::endl << correct << std::endl;
+        return 1;
+    }
+    else {
+        std::cout << result.str();
+        return 0;
+    }
+}
+
+int main(int argc, char* argv[])
+{
+    int result = 0;
+
+    result += test1();
+    result += test3();
+    result += test4();
+    result += test5();
+    result += test6();
+
+    return result;
+}
+
+// $Id: TestHLAtypes.cc,v 1.1 2008/11/06 16:18:38 gotthardp Exp $




reply via email to

[Prev in Thread] Current Thread [Next in Thread]