Browse Source

[trac1062] update tests

Jelte Jansen 13 years ago
parent
commit
1b96c25633

+ 1 - 0
src/lib/datasrc/sqlite3_connection.cc

@@ -359,6 +359,7 @@ SQLite3Connection::getNextRecord(std::vector<std::string>& columns) const {
         return false;
     }
     sqlite3_reset(current_stmt);
+    sqlite3_clear_bindings(current_stmt);
     isc_throw(DataSourceError, "Unexpected failure in sqlite3_step");
 
     // Compilers might not realize isc_throw always throws

+ 36 - 0
src/lib/datasrc/tests/sqlite3_connection_unittest.cc

@@ -100,4 +100,40 @@ TEST_F(SQLite3Conn, noClass) {
     EXPECT_FALSE(conn->getZone(Name("example.com")).first);
 }
 
+namespace {
+    // Simple function to cound the number of records for
+    // any name
+    size_t countRecords(std::auto_ptr<SQLite3Connection>& conn,
+                        int zone_id, const std::string& name) {
+        conn->searchForRecords(zone_id, name);
+        size_t count = 0;
+        std::vector<std::string> columns;
+        while (conn->getNextRecord(columns)) {
+            EXPECT_EQ(4, columns.size());
+            ++count;
+        }
+        return count;
+    }
+}
+}
+
+TEST_F(SQLite3Conn, getRecords) {
+    std::pair<bool, int> zone_info(conn->getZone(Name("example.com")));
+    ASSERT_TRUE(zone_info.first);
+
+    int zone_id = zone_info.second;
+    ASSERT_EQ(1, zone_id);
+
+    // without search, getNext() should return false
+    std::vector<std::string> columns;
+    EXPECT_FALSE(conn->getNextRecord(columns));
+    EXPECT_EQ(0, columns.size());
+
+    EXPECT_EQ(4, countRecords(conn, zone_id, "foo.example.com."));
+    EXPECT_EQ(15, countRecords(conn, zone_id, "example.com."));
+    EXPECT_EQ(0, countRecords(conn, zone_id, "foo.bar."));
+    EXPECT_EQ(0, countRecords(conn, zone_id, ""));
+
+    EXPECT_FALSE(conn->getNextRecord(columns));
+    EXPECT_EQ(0, columns.size());
 }