susumu.yata
null+****@clear*****
Thu Dec 4 15:34:15 JST 2014
susumu.yata 2014-12-04 15:34:15 +0900 (Thu, 04 Dec 2014) New Revision: 6a85dc651486a6908198e4c31c16878481faf677 https://github.com/groonga/grnxx/commit/6a85dc651486a6908198e4c31c16878481faf677 Message: Add a test for Index::test_uniqueness(). (#125) Modified files: test/test_index.cpp Modified: test/test_index.cpp (+41 -0) =================================================================== --- test/test_index.cpp 2014-12-04 15:33:57 +0900 (4225ac9) +++ test/test_index.cpp 2014-12-04 15:34:15 +0900 (d0cfa3a) @@ -853,6 +853,45 @@ void test_offset_and_limit() { } } +void test_uniqueness() { + // Create a column. + auto db = grnxx::open_db(""); + auto table = db->create_table("Table"); + auto column = table->create_column("Column", grnxx::INT_DATA); + + // Create an index. + auto index = column->create_index("Index", grnxx::TREE_INDEX); + assert(index->test_uniqueness()); + + grnxx::Int row_id = table->insert_row(); + assert(index->test_uniqueness()); + column->set(row_id, grnxx::Int(123)); + assert(index->test_uniqueness()); + + row_id = table->insert_row(); + assert(index->test_uniqueness()); + column->set(row_id, grnxx::Int(456)); + assert(index->test_uniqueness()); + + row_id = table->insert_row(); + assert(index->test_uniqueness()); + column->set(row_id, grnxx::Int::na()); + assert(index->test_uniqueness()); + + row_id = table->insert_row(); + assert(index->test_uniqueness()); + column->set(row_id, grnxx::Int::na()); + assert(index->test_uniqueness()); + + row_id = table->insert_row(); + assert(index->test_uniqueness()); + column->set(row_id, grnxx::Int(123)); + assert(!index->test_uniqueness()); + + table->remove_row(row_id); + assert(index->test_uniqueness()); +} + int main() { test_index(); @@ -874,5 +913,7 @@ int main() { test_reverse(); test_offset_and_limit(); + test_uniqueness(); + return 0; } -------------- next part -------------- HTML����������������������������... 下載