[glom] Test some query functions.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Test some query functions.
- Date: Tue, 18 Oct 2011 19:32:51 +0000 (UTC)
commit db63ba66257b75ef38ce92e6c29d51ef240d51d7
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Oct 18 21:32:35 2011 +0200
Test some query functions.
* tests/test_selfhosting_utils.[h|cc]: Added test_model_expected_size().
* tests/test_selfhosting_new_from_example.cc: Test the quick find and
the count query.
ChangeLog | 8 ++++
tests/test_selfhosting_new_from_example.cc | 60 ++++++++++++++++++++++++++++
tests/test_selfhosting_utils.cc | 24 +++++++++++
tests/test_selfhosting_utils.h | 4 ++
4 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f28f3bc..ad59e77 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2011-10-18 Murray Cumming <murrayc murrayc com>
+ Test some query functions.
+
+ * tests/test_selfhosting_utils.[h|cc]: Added test_model_expected_size().
+ * tests/test_selfhosting_new_from_example.cc: Test the quick find and
+ the count query.
+
+2011-10-18 Murray Cumming <murrayc murrayc com>
+
Avoid a compiler warning.
* glom/libglom/data_structure/glomconversions.cc: format_time():
diff --git a/tests/test_selfhosting_new_from_example.cc b/tests/test_selfhosting_new_from_example.cc
index e8864c8..6c92599 100644
--- a/tests/test_selfhosting_new_from_example.cc
+++ b/tests/test_selfhosting_new_from_example.cc
@@ -20,6 +20,8 @@
#include "tests/test_selfhosting_utils.h"
#include <libglom/init.h>
+#include <libglom/utils.h>
+#include <libglom/db_utils.h>
#include <glib.h> //For g_assert()
#include <iostream>
#include <cstdlib> //For EXIT_SUCCESS and EXIT_FAILURE
@@ -33,6 +35,64 @@ int main()
test_create_and_selfhost("example_music_collection.glom", document);
g_assert(recreated);
+ //Check that some data is as expected:
+ const Gnome::Gda::Value value("Born To Run");
+ const Gnome::Gda::SqlExpr where_clause =
+ Glom::Utils::get_find_where_clause_quick(&document, "albums", value);
+
+ Glom::Utils::type_vecLayoutFields fieldsToGet;
+ Glom::sharedptr<const Glom::Field> field = document.get_field("albums", "album_id");
+ Glom::sharedptr<Glom::LayoutItem_Field> layoutitem = Glom::sharedptr<Glom::LayoutItem_Field>::create();
+ layoutitem->set_full_field_details(field);
+ fieldsToGet.push_back(layoutitem);
+ field = document.get_field("albums", "name");
+ layoutitem = Glom::sharedptr<Glom::LayoutItem_Field>::create();
+ layoutitem->set_full_field_details(field);
+ fieldsToGet.push_back(layoutitem);
+
+ const Glib::RefPtr<const Gnome::Gda::SqlBuilder> builder =
+ Glom::Utils::build_sql_select_with_where_clause("albums",
+ fieldsToGet, where_clause);
+ Glib::RefPtr<Gnome::Gda::DataModel> data_model =
+ Glom::DbUtils::query_execute_select(builder);
+ if(!test_model_expected_size(data_model, 2, 1))
+ {
+ std::cerr << "Failure: Unexpected data model size for main query." << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ const Glib::RefPtr<const Gnome::Gda::SqlBuilder> builder_count =
+ Glom::Utils::build_sql_select_count_rows(builder);
+ data_model =
+ Glom::DbUtils::query_execute_select(builder_count);
+ if(!test_model_expected_size(data_model, 1, 1))
+ {
+ std::cerr << "Failure: Unexpected data model size for count query." << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ int result = 0;
+ const Gnome::Gda::Value value_count = data_model->get_value_at(0, 0);
+ if(value_count.get_value_type() == G_TYPE_INT64)
+ {
+ result = (int)value_count.get_int64();
+ }
+ else
+ {
+ std::cerr << "Failure: The COUNT query returned an unexpected data type." << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ if(result != 1)
+ {
+ std::cerr << "Failure: The COUNT query returned an unexpected value." << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
test_selfhosting_cleanup();
Glom::libglom_deinit();
diff --git a/tests/test_selfhosting_utils.cc b/tests/test_selfhosting_utils.cc
index 0bc5406..d6e76dd 100644
--- a/tests/test_selfhosting_utils.cc
+++ b/tests/test_selfhosting_utils.cc
@@ -201,3 +201,27 @@ bool test_create_and_selfhost(const std::string& example_filename, Glom::Documen
return recreated;
}
+bool test_model_expected_size(const Glib::RefPtr<Gnome::Gda::DataModel>& data_model, guint columns_count, guint rows_count)
+{
+ if(!data_model)
+ {
+ std::cerr << "Failure: data_model was null" << std::endl;
+ return false;
+ }
+
+ if(data_model->get_n_columns() != (int)columns_count)
+ {
+ std::cerr << "Failure: get_n_columns() returned an unexpected value. Expected: " << columns_count << ", Actual: " << data_model->get_n_columns() << std::endl;
+ return false;
+ }
+
+ if(data_model->get_n_rows() != (int)rows_count)
+ {
+ std::cerr << "Failure: get_n_rows() returned an unexpected value. Expected: " << rows_count << ", Actual: " << data_model->get_n_rows() << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+
diff --git a/tests/test_selfhosting_utils.h b/tests/test_selfhosting_utils.h
index 412d83b..638e445 100644
--- a/tests/test_selfhosting_utils.h
+++ b/tests/test_selfhosting_utils.h
@@ -22,9 +22,13 @@
#define GLOM_TEST_SELFHOSTING_UTILS_H
#include <libglom/document/document.h>
+#include <libgdamm/datamodel.h>
#include <string>
bool test_create_and_selfhost(const std::string& example_filename, Glom::Document& document);
+
+bool test_model_expected_size(const Glib::RefPtr<Gnome::Gda::DataModel>& data_model, guint columns_count, guint rows_count);
+
void test_selfhosting_cleanup();
#endif //GLOM_TEST_SELFHOSTING_UTILS_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]