susumu.yata
null+****@clear*****
Tue Dec 16 10:45:31 JST 2014
susumu.yata 2014-11-25 10:16:09 +0900 (Tue, 25 Nov 2014) New Revision: 37401ea541dd1c59f5edc715260c33b6374bceaf https://github.com/groonga/grnxx/commit/37401ea541dd1c59f5edc715260c33b6374bceaf Message: Enable a test for Int key. Modified files: test/test_table.cpp Modified: test/test_table.cpp (+57 -68) =================================================================== --- test/test_table.cpp 2014-11-25 10:16:02 +0900 (4215bbe) +++ test/test_table.cpp 2014-11-25 10:16:09 +0900 (161b040) @@ -207,76 +207,65 @@ void test_bitmap() { assert(table->max_row_id().value() == (NUM_ROWS - 1)); } -//void test_int_key() { -// // TODO: find_row() is not supported yet. -// grnxx::Error error; - -// // Create a database with the default options. -// auto db = grnxx::open_db(&error, ""); -// assert(db); - -// // Create a table named "Table". -// auto table = db->create_table(&error, "Table"); -// assert(table); - -// // Create a column named "Column". -// auto column = table->create_column(&error, "Column", grnxx::INT_DATA); -// assert(column); - -// // Append three rows. -// grnxx::Int row_id; -// assert(table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Datum(), &row_id)); -// assert(column->set(&error, row_id, grnxx::Int(1))); -// assert(table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Datum(), &row_id)); -// assert(column->set(&error, row_id, grnxx::Int(10))); -// assert(table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Datum(), &row_id)); -// assert(column->set(&error, row_id, grnxx::Int(100))); - -// // Set key column. -// assert(table->set_key_column(&error, "Column")); -// assert(table->key_column() == column); - -// // Duplicate keys must be rejected. -// assert(!table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Int(1), &row_id)); -// assert(row_id == 1); -// assert(!table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Int(10), &row_id)); -// assert(row_id == 2); -// assert(!table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Int(100), &row_id)); -// assert(row_id == 3); +void test_int_key() { + // Create a database with the default options. + auto db = grnxx::open_db(""); -// // Append new keys. -// grnxx::Datum datum; -// assert(table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Int(2), &row_id)); -// assert(column->get(&error, row_id, &datum)); -// assert(datum.force_int() == 2); -// assert(table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Int(20), &row_id)); -// assert(column->get(&error, row_id, &datum)); -// assert(datum.force_int() == 20); -// assert(table->insert_row(&error, grnxx::NULL_ROW_ID, -// grnxx::Int(200), &row_id)); -// assert(column->get(&error, row_id, &datum)); -// assert(datum.force_int() == 200); + // Create a table named "Table". + auto table = db->create_table("Table"); -// // Find rows by key. -// assert(table->find_row(&error, grnxx::Int(1)) == 1); -// assert(table->find_row(&error, grnxx::Int(10)) == 2); -// assert(table->find_row(&error, grnxx::Int(100)) == 3); -// assert(table->find_row(&error, grnxx::Int(2)) == 4); -// assert(table->find_row(&error, grnxx::Int(20)) == 5); -// assert(table->find_row(&error, grnxx::Int(200)) == 6); + // Create a column named "Column". + auto column = table->create_column("Column", grnxx::INT_DATA); -// // Unset key column. -// assert(table->unset_key_column(&error)); -// assert(!table->key_column()); -//} + // Append three rows. + grnxx::Int row_id = table->insert_row(); + column->set(row_id, grnxx::Int(1)); + row_id = table->insert_row(); + column->set(row_id, grnxx::Int(10)); + row_id = table->insert_row(); + column->set(row_id, grnxx::Int(100)); + + // Set key column. + table->set_key_column("Column"); + assert(table->key_column() == column); + + // Duplicate keys must be rejected. + bool inserted = true; + row_id = table->find_or_insert_row(grnxx::Int(1), &inserted); + assert(row_id.match(grnxx::Int(0))); + assert(!inserted); + row_id = table->find_or_insert_row(grnxx::Int(10), &inserted); + assert(row_id.match(grnxx::Int(1))); + assert(!inserted); + row_id = table->find_or_insert_row(grnxx::Int(100), &inserted); + assert(row_id.match(grnxx::Int(2))); + assert(!inserted); + + // Append new keys. + grnxx::Datum datum; + row_id = table->find_or_insert_row(grnxx::Int(2), &inserted); + assert(inserted); + column->get(row_id, &datum); + assert(datum.as_int().value() == 2); + row_id = table->find_or_insert_row(grnxx::Int(20), &inserted); + column->get(row_id, &datum); + assert(datum.as_int().value() == 20); + row_id = table->find_or_insert_row(grnxx::Int(200), &inserted); + column->get(row_id, &datum); + assert(datum.as_int().value() == 200); + + // Find rows by key. + assert(table->find_row(grnxx::Int(1)).value() == 0); + assert(table->find_row(grnxx::Int(10)).value() == 1); + assert(table->find_row(grnxx::Int(100)).value() == 2); + assert(table->find_row(grnxx::Int(2)).value() == 3); + assert(table->find_row(grnxx::Int(20)).value() == 4); + assert(table->find_row(grnxx::Int(200)).value() == 5); + + // Unset key column. + table->unset_key_column(); + assert(!table->key_column()); +} //void test_text_key() { // // TODO: find_row() is not supported yet. @@ -478,7 +467,7 @@ int main() { test_table(); test_rows(); test_bitmap(); -// test_int_key(); + test_int_key(); // test_text_key(); test_cursor(); test_reference(); -------------- next part -------------- HTML����������������������������... 下載