File: myx_catalogs_test.cpp

package info (click to toggle)
mysql-query-browser 1.2.5beta-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 63,792 kB
  • ctags: 46,485
  • sloc: pascal: 249,299; ansic: 80,111; cpp: 72,467; sh: 25,271; objc: 20,015; yacc: 10,755; java: 9,917; xml: 4,580; php: 2,806; python: 1,566; sql: 1,563; makefile: 1,452; perl: 3
file content (194 lines) | stat: -rw-r--r-- 6,637 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

// This file contains common TUT test cases for myx_catalogs.c
//
//

//----------------------------------------------------------------------------------------------------------------------

#include "test.h"
#include "myx_public_interface.h"

// Private test data.
BEGIN_TEST_DATA_CLASS(module2_catalog_test)
protected:
  Test_connection* connection;
END_TEST_DATA_CLASS

//----------------------------------------------------------------------------------------------------------------------

TEST_MODULE(module2_catalog_test, "Common test suite, base library");

//----------------------------------------------------------------------------------------------------------------------

static const char * show_master_status_fields[]=
{
  "File",               // 0
  "Position",           // 1
  "Binlog_Do_DB",       // 2
  "Binlog_Ignore_DB"    // 3
};
static const char ** show_master_status_fields_end= show_master_status_fields +
  sizeof(show_master_status_fields) / sizeof(char*);

TEST_FUNCTION(5)
{
  connection= test_group_singleton.get_connection();
  ensure("Valid server connection", connection != NULL);

  Resultset* resultset = connection->new_resultset("SHOW MASTER STATUS");
  ensure("Query SHOW MASTER STATUS", resultset != NULL);

  MYSQL_FIELD *fields;
  int num_fields;
  int fi[4];

  num_fields= resultset->get_column_count();
  fields= resultset->get_column_fields();
  build_field_subst(show_master_status_fields, show_master_status_fields_end, fields, fields + num_fields, fi);

  for (int i = 0; i < sizeof(show_master_status_fields) / sizeof(char*); i++)
  {
    ensure("build_field_subst", fi[i] == i);
  }

  delete resultset;
}

//----------------------------------------------------------------------------------------------------------------------

TEST_FUNCTION(10)
{
  connection->query("DROP FUNCTION IF EXISTS `test`.`test_17096`");
  connection->query("CREATE FUNCTION `test`.`test_17096`() RETURNS int(11) BEGIN return 1; END");

  Auto_release ar;
  MYX_SCHEMA_STORED_PROCEDURES *sps= ar.add(myx_get_schema_sps(connection->get_mysql(), "def", "test"));
  for (unsigned int i= 0; i < sps->schema_sps_num; i++)
  {
    if (strcmp2(sps->schema_sps[i].name, "test_17096") == 0)
    {
      ensure("Number of created routines", strcmp2(sps->schema_sps[i].return_datatype, "int(11)") == 0);
      connection->query("DROP FUNCTION IF EXISTS `test`.`test_17096`");
      break;
    }
  }
}

//----------------------------------------------------------------------------------------------------------------------

typedef struct
{
  std::string name;
  std::string type;
} table_test_entry;

static const table_test_entry table_test_data[]=
{
  {"actor", "InnoDB"},
  {"address", "InnoDB"},
  {"category", "InnoDB"},
  {"city", "InnoDB"},
  {"country", "InnoDB"},
  {"customer", "InnoDB"},
  {"film", "InnoDB"},
  {"film_actor", "InnoDB"},
  {"film_category", "InnoDB"},
  {"film_text", "MyISAM"},
  {"inventory", "InnoDB"},
  {"language", "InnoDB"},
  {"payment", "InnoDB"},
  {"rental", "InnoDB"},
  {"staff", "InnoDB"},
  {"store", "InnoDB"}
};
unsigned int table_test_entries= sizeof(table_test_data) / sizeof(table_test_entry);

TEST_FUNCTION(15)
{
  MYSQL* mysql= connection->get_mysql();
  Auto_release releaser;

  // Test getting schema tables.
  MYX_SCHEMA_TABLE_STATUS* table_status;

  // Start with invalid schema.
  table_status= myx_get_schema_table_status(mysql, NULL, "dummy");
  ensure("Invalid schema", table_status == NULL);

  // Empty schema. Ensure the test schema is deleted even in case of a failure.
  releaser.add_sql(connection, "drop schema if exists catalogs_test");

  connection->query("create schema catalogs_test");
  connection->query("use catalogs_test"); // Throws a logic error if it fails.
  table_status= myx_get_schema_table_status(mysql, NULL, "catalogs_test");
  ensure("Empty schema", table_status != NULL);
  ensure("Empty schema", table_status->schema_tables == NULL);
  connection->query("drop schema catalogs_test");
  myx_free_schema_table_status(table_status);

  // Finally check a schema with content.
  table_status= myx_get_schema_table_status(mysql, NULL, "sakila");
  ensure("Table count", table_status->schema_tables_num == table_test_entries);
  for (unsigned int i = 0; i < table_test_entries; i++)
  {
    ensure("Table name", table_status->schema_tables[i].table_name == table_test_data[i].name);
    ensure("Table type", table_status->schema_tables[i].table_type == table_test_data[i].type);
  };

  myx_free_schema_table_status(table_status);
}

//----------------------------------------------------------------------------------------------------------------------

static const std::string view_test_data[]=
{
  "actor_info",
  "customer_list",
  "film_list",
  "nicer_but_slower_film_list",
  "sales_by_film_category",
  "sales_by_store",
  "staff_list"
};
unsigned int view_test_entries= sizeof(view_test_data) / sizeof(std::string);

TEST_FUNCTION(20)
{
  MYSQL* mysql= connection->get_mysql();
  Auto_release releaser;

  // Test getting schema views.
  MYX_SCHEMA_VIEW_STATUS* view_status;

  // Start with invalid schema.
  view_status= myx_get_schema_view_status(mysql, NULL, "dummy");
  ensure("Invalid schema", view_status == NULL);

  // Empty schema. Ensure the test schema is deleted even in case of a failure.
  releaser.add_sql(connection, "drop schema if exists catalogs_test");

  connection->query("create schema catalogs_test");
  connection->query("use catalogs_test"); // Throws a logic error if it fails.
  view_status= myx_get_schema_view_status(mysql, NULL, "catalogs_test");
  ensure("Empty schema", view_status != NULL);
  ensure("Empty schema", view_status->schema_views == NULL);
  connection->query("drop schema catalogs_test");
  myx_free_schema_view_status(view_status);

  // Finally check a schema with content.
  view_status= myx_get_schema_view_status(mysql, NULL, "sakila");
  ensure("View count", view_status->schema_views_num == view_test_entries);
  for (unsigned int i = 0; i < view_test_entries; i++)
  {
    ensure("View name", view_status->schema_views[i].view_name == view_test_data[i]);
  };

  myx_free_schema_view_status(view_status);
}

//----------------------------------------------------------------------------------------------------------------------

END_TESTS;

//----------------------------------------------------------------------------------------------------------------------