Mercurial Hosting > traffic-intelligence
comparison trajectorymanagement/test/TrajectoryDBAccessTest.h @ 1159:e1e7acef8eab
moved trajectory management library into Traffic Intelligence
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 22 Feb 2021 22:09:35 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1158:7eb972942f22 | 1159:e1e7acef8eab |
---|---|
1 #ifndef TRAJECTORYDBACCESSTEST_H_ | |
2 #define TRAJECTORYDBACCESSTEST_H_ | |
3 #include <cppunit/extensions/HelperMacros.h> | |
4 #include "../src/TrajectoryDBAccess.h" | |
5 using namespace std; | |
6 | |
7 template<typename T> | |
8 class TrajectoryDBAccessTest: public CPPUNIT_NS::TestCase | |
9 { | |
10 public: | |
11 virtual void setUp(void) | |
12 { | |
13 dbName = "XXXXXX.sqlite"; | |
14 int res = mkstemps((char*) dbName.c_str(), 7); | |
15 CPPUNIT_ASSERT(res != -1); | |
16 } | |
17 | |
18 void tearDown(void) | |
19 { | |
20 delete db; | |
21 unlink(dbName.c_str()); | |
22 } | |
23 | |
24 protected: | |
25 void testSize(void) | |
26 { | |
27 T point; | |
28 initPoint(point, 1, 2, 3); | |
29 | |
30 CPPUNIT_ASSERT_EQUAL(true, db->connect(dbName.c_str())); | |
31 CPPUNIT_ASSERT_EQUAL(true, db->createTable()); | |
32 | |
33 unsigned int size; | |
34 | |
35 for (unsigned int i = 0; i < 100; ++i) | |
36 { | |
37 CPPUNIT_ASSERT_EQUAL(true, db->size(size)); | |
38 CPPUNIT_ASSERT_EQUAL(i, size); | |
39 | |
40 Trajectory<T> trajectory; | |
41 trajectory.setId(i); | |
42 trajectory.add(i, point); | |
43 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory)); | |
44 trajectory.pop_back(); | |
45 } | |
46 | |
47 CPPUNIT_ASSERT_EQUAL(true, db->size(size)); | |
48 CPPUNIT_ASSERT_EQUAL((unsigned int) 100, size); | |
49 } | |
50 | |
51 void testMinTrajectoryId(void) | |
52 { | |
53 T point; | |
54 initPoint(point, 1, 2, 3); | |
55 | |
56 Trajectory<T> trajectory[4]; | |
57 for (unsigned int i = 0; i < 4; ++i) | |
58 { | |
59 trajectory[i].setId(i + 1); | |
60 trajectory[i].add(i, point); | |
61 } | |
62 | |
63 CPPUNIT_ASSERT_EQUAL(true, db->connect(dbName.c_str())); | |
64 CPPUNIT_ASSERT_EQUAL(true, db->createTable()); | |
65 | |
66 unsigned int id; | |
67 | |
68 CPPUNIT_ASSERT_EQUAL(false, db->minTrajectoryId(id)); | |
69 | |
70 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory[1])); | |
71 CPPUNIT_ASSERT_EQUAL(true, db->minTrajectoryId(id)); | |
72 CPPUNIT_ASSERT_EQUAL((unsigned int) 2, id); | |
73 | |
74 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory[2])); | |
75 CPPUNIT_ASSERT_EQUAL(true, db->minTrajectoryId(id)); | |
76 CPPUNIT_ASSERT_EQUAL((unsigned int) 2, id); | |
77 | |
78 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory[0])); | |
79 CPPUNIT_ASSERT_EQUAL(true, db->minTrajectoryId(id)); | |
80 CPPUNIT_ASSERT_EQUAL((unsigned int) 1, id); | |
81 | |
82 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory[3])); | |
83 CPPUNIT_ASSERT_EQUAL(true, db->minTrajectoryId(id)); | |
84 CPPUNIT_ASSERT_EQUAL((unsigned int) 1, id); | |
85 } | |
86 | |
87 void testMaxTrajectoryId(void) | |
88 { | |
89 T point; | |
90 initPoint(point, 1, 2, 3); | |
91 | |
92 Trajectory<T> trajectory[4]; | |
93 for (unsigned int i = 0; i < 4; ++i) | |
94 { | |
95 trajectory[i].setId(i + 1); | |
96 trajectory[i].add(i, point); | |
97 } | |
98 | |
99 CPPUNIT_ASSERT_EQUAL(true, db->connect(dbName.c_str())); | |
100 CPPUNIT_ASSERT_EQUAL(true, db->createTable()); | |
101 | |
102 unsigned int id; | |
103 | |
104 CPPUNIT_ASSERT_EQUAL(false, db->maxTrajectoryId(id)); | |
105 | |
106 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory[1])); | |
107 CPPUNIT_ASSERT_EQUAL(true, db->maxTrajectoryId(id)); | |
108 CPPUNIT_ASSERT_EQUAL((unsigned int) 2, id); | |
109 | |
110 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory[2])); | |
111 CPPUNIT_ASSERT_EQUAL(true, db->maxTrajectoryId(id)); | |
112 CPPUNIT_ASSERT_EQUAL((unsigned int) 3, id); | |
113 | |
114 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory[0])); | |
115 CPPUNIT_ASSERT_EQUAL(true, db->maxTrajectoryId(id)); | |
116 CPPUNIT_ASSERT_EQUAL((unsigned int) 3, id); | |
117 | |
118 CPPUNIT_ASSERT_EQUAL(true, db->write(trajectory[3])); | |
119 CPPUNIT_ASSERT_EQUAL(true, db->maxTrajectoryId(id)); | |
120 CPPUNIT_ASSERT_EQUAL((unsigned int) 4, id); | |
121 } | |
122 | |
123 void testPrototypeMatchStructure(void){ | |
124 | |
125 CPPUNIT_ASSERT_EQUAL(true, db->connect(dbName.c_str())); | |
126 CPPUNIT_ASSERT_EQUAL(true, db->createPrototypeTable()); | |
127 multimap<int,int> matches; | |
128 for (int i = 0 ; i < 5 ; i++) | |
129 matches.insert(pair<int,int>(i,i)); | |
130 | |
131 CPPUNIT_ASSERT_EQUAL(true, db->write(matches)); | |
132 | |
133 multimap<int,int> rematches; | |
134 CPPUNIT_ASSERT_EQUAL(true, db->read(rematches)); | |
135 multimap<int,int>::iterator it_rematches; | |
136 multimap<int,int>::iterator it_matches (matches.begin()); | |
137 for (it_rematches = rematches.begin() ; it_rematches != rematches.end() ; it_rematches++){ | |
138 CPPUNIT_ASSERT_EQUAL(it_rematches->first, it_matches->first); | |
139 CPPUNIT_ASSERT_EQUAL(it_rematches->second,it_matches->second); | |
140 advance(it_matches, 1); | |
141 } // for iterator | |
142 | |
143 } // testPrototypeMatchStructure | |
144 | |
145 TrajectoryDBAccess<T> *db; | |
146 | |
147 string dbName; | |
148 }; | |
149 | |
150 #endif /* TRAJECTORYDBACCESSTEST_H_ */ |