[libgda] DbIndex: Adding test for DdlModifiable interface



commit 335eb1e8941164270638a3058c14427d80c18fbe
Author: Pavlo Solntsev <p sun fun gmail com>
Date:   Sat May 30 22:35:51 2020 -0500

    DbIndex: Adding test for DdlModifiable interface
    
    Test for RENAME operation on index was added

 tests/test-server-operation-sqlite.c | 87 ++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
---
diff --git a/tests/test-server-operation-sqlite.c b/tests/test-server-operation-sqlite.c
index f7e6ca562..739d81c63 100644
--- a/tests/test-server-operation-sqlite.c
+++ b/tests/test-server-operation-sqlite.c
@@ -35,6 +35,8 @@
  *
  */
 #include "gda-db-column.h"
+#include "gda-db-index-field.h"
+#include "gda-db-index.h"
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <locale.h>
@@ -1110,6 +1112,84 @@ test_server_operation_operations_db_unsupported (TestObjectFixture *fixture,
   g_object_unref (tproject);
 }
 
+static void
+test_server_operation_operations_db_index (TestObjectFixture *fixture,
+                                          G_GNUC_UNUSED gconstpointer user_data)
+{
+  /* Define table Project */
+  GdaDbTable *tproject = gda_db_table_new ();
+  gda_db_base_set_name (GDA_DB_BASE (tproject), "Project");
+  gda_db_table_set_is_temp (tproject, FALSE);
+
+  /* Defining column id */
+  GdaDbColumn *pid = gda_db_column_new ();
+  gda_db_column_set_name (pid, "id");
+  gda_db_column_set_type (pid, G_TYPE_INT);
+  gda_db_column_set_nnul (pid, TRUE);
+  gda_db_column_set_autoinc (pid, TRUE);
+  gda_db_column_set_unique (pid, TRUE);
+  gda_db_column_set_pkey (pid, TRUE);
+
+  gda_db_table_append_column (tproject, pid);
+
+  g_object_unref (pid);
+
+  /* Defining column name */
+  GdaDbColumn *pname = gda_db_column_new ();
+  gda_db_column_set_name (pname, "name");
+  gda_db_column_set_type (pname, G_TYPE_STRING);
+  gda_db_column_set_size (pname, 50);
+  gda_db_column_set_nnul (pname, TRUE);
+  gda_db_column_set_autoinc (pname, FALSE);
+  gda_db_column_set_unique (pname, TRUE);
+  gda_db_column_set_pkey (pname, FALSE);
+  gda_db_column_set_default (pname, "Default_name");
+
+  gda_db_table_append_column (tproject, pname);
+
+  g_object_unref (pname);
+
+/* Create table */
+  gboolean res = gda_ddl_modifiable_create (GDA_DDL_MODIFIABLE (tproject), fixture->cnc, NULL, NULL);
+
+  g_assert_true (res);
+
+  GError *error = NULL;
+  res = gda_ddl_modifiable_drop (GDA_DDL_MODIFIABLE (pname), fixture->cnc, tproject, &error);
+
+  if (error != NULL) {
+    g_print ("Error: %s\n", error->message != NULL ? error->message : "No detail");
+    g_clear_error (&error);
+  }
+
+  g_assert_false (res);
+
+  g_clear_error (&error);
+
+  GdaDbIndex *index = gda_db_index_new ();
+
+  gda_db_base_set_name (GDA_DB_BASE (index), "simpleindex");
+
+  GdaDbIndexField *ifield = gda_db_index_field_new ();
+  gda_db_index_field_set_column (ifield, pname);
+
+  gda_db_index_append_field (index, ifield);
+  g_object_unref (ifield);
+
+  g_object_set (index, "table", gda_db_base_get_name (GDA_DB_BASE (tproject)), NULL);
+
+  res = gda_ddl_modifiable_rename (GDA_DDL_MODIFIABLE (index), fixture->cnc, "newindex", &error);
+
+  if (error != NULL) {
+    g_print ("Error: %s\n", error->message != NULL ? error->message : "No detail");
+    g_clear_error (&error);
+  }
+
+  g_assert_true (res);
+  g_object_unref (index);
+  g_object_unref (tproject);
+}
+
 gint
 main(gint argc, gchar *argv[])
 {
@@ -1144,6 +1224,13 @@ main(gint argc, gchar *argv[])
               test_server_operation_start,
               test_server_operation_operations_db_unsupported,
               test_server_operation_finish);
+
+  g_test_add ("/test-server-operation-sqlite/gda-db-index",
+              TestObjectFixture,
+              NULL,
+              test_server_operation_start,
+              test_server_operation_operations_db_index,
+              test_server_operation_finish);
   return g_test_run();
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]