comparison TestMemoryDBLink.cpp @ 76:8136057988bc

Fixes to automatic report generating system. A lot of new unittests.
author Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no>
date Sat, 16 Feb 2013 15:32:20 +0100
parents c9447697609f
children 9744ec195be3
comparison
equal deleted inserted replaced
75:aaf0a2878f67 76:8136057988bc
4 4
5 BOOST_AUTO_TEST_CASE( AddUpdateDeleteFile ) 5 BOOST_AUTO_TEST_CASE( AddUpdateDeleteFile )
6 { 6 {
7 MemoryDBLink link; 7 MemoryDBLink link;
8 8
9 QDateTime time1; 9 QDateTime time1 = QDateTime::currentDateTime();
10 QDateTime time2 = time1.addSecs(1); 10 QDateTime time2 = time1.addSecs(1);
11 11
12 BOOST_REQUIRE(!link.exists("test"));
12 BOOST_REQUIRE_EQUAL(link.existsWithMtime("test", time1), FileDBLink::NONE); 13 BOOST_REQUIRE_EQUAL(link.existsWithMtime("test", time1), FileDBLink::NONE);
13 link.addFile("test", 1, time1, "a"); 14 link.addFile("test", 1, time1, "a");
14 BOOST_REQUIRE_EQUAL(link.existsWithMtime("test", time1), FileDBLink::SAME); 15 BOOST_REQUIRE_EQUAL(link.existsWithMtime("test", time1), FileDBLink::SAME);
16 BOOST_REQUIRE(link.exists("test"));
15 BOOST_REQUIRE_THROW(link.addFile("test", 1, time1, "a"), 17 BOOST_REQUIRE_THROW(link.addFile("test", 1, time1, "a"),
16 ValueExistsException); 18 ValueExistsException);
17 19
18 link.updateFile("test", 1, time2, "a"); 20 link.updateFile("test", 1, time2, "a");
19 BOOST_REQUIRE_EQUAL(link.existsWithMtime("test", time1), FileDBLink::MTIME_DIFFERENT); 21 BOOST_REQUIRE_EQUAL(link.existsWithMtime("test", time1), FileDBLink::MTIME_DIFFERENT);
22 BOOST_REQUIRE(link.exists("test"));
20 BOOST_REQUIRE_THROW(link.addFile("test", 1, time1, "a"), 23 BOOST_REQUIRE_THROW(link.addFile("test", 1, time1, "a"),
21 ValueExistsException); 24 ValueExistsException);
22 25
23 /* 26
24 BOOST_REQUIRE(!map.find(k4));
25 map.insert(k4);
26 BOOST_WARN_EQUAL(map.depth(), 2u);
27 BOOST_WARN_EQUAL(map.total_depth(), 8u);
28 BOOST_REQUIRE_EQUAL(map.size(), 4u);
29 BOOST_REQUIRE_EQUAL(map.optimal_depth(), 3u);
30 BOOST_REQUIRE_THROW(map.insert(k4), ValueExistsException);
31 BOOST_REQUIRE(map.find(k1));
32 BOOST_REQUIRE_EQUAL(*map.find(k1), k1);
33 BOOST_REQUIRE(map.find(k2));
34 BOOST_REQUIRE_EQUAL(*map.find(k2), k2);
35 BOOST_REQUIRE(map.find(k4));
36 BOOST_REQUIRE_EQUAL(*map.find(k4), k4);
37 */
38 } 27 }
28
29 BOOST_AUTO_TEST_CASE( SortUnsortable )
30 {
31 MemoryDBLink link;
32
33 QString path1 = "a";
34 int size1 = 1;
35 QDateTime time1 = QDateTime::currentDateTime();
36 QByteArray checksum1 = QByteArray::fromHex("a");
37
38 QString path2 = "b";
39 int size2 = 2;
40 QDateTime time2 = time1.addSecs(1);
41 QByteArray checksum2 = QByteArray::fromHex("b");
42
43
44 link.addFile(path2, size2, time2, checksum2);
45 link.addFile(path1, size1, time1, checksum1);
46
47
48 {
49 QList<FileDBLink::dbinf_ptr_t > out;
50 out = link.sortOn("", FileDBLink::PATH, false);
51
52 bool first = true;
53 QString prev;
54 foreach(FileDBLink::dbinf_ptr_t info, out) {
55 if (first) {
56 first = false;
57 }
58 else {
59 BOOST_REQUIRE(prev <= info->path());
60 }
61 prev = info->path();
62 }
63 }
64
65 }