~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to modules/wb.mysql.import/unit-tests/test_wb_mysql_import_dbd4.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; version 2 of the
 
7
 * License.
 
8
 * 
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
 * GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
#include "tut_stdafx.h"
 
21
 
 
22
#ifndef _WIN32
 
23
#include <sstream>
 
24
#include <fstream>
 
25
#endif
 
26
 
 
27
#include "testgrt.h"
 
28
#include "grt_test_utility.h"
 
29
#include "grts/structs.db.mgmt.h"
 
30
#include "grts/structs.db.mysql.h"
 
31
#include "grts/structs.workbench.physical.h"
 
32
#include "wb_mysql_import.h"
 
33
#include "grt/grt_manager.h"
 
34
#include "wb_mysql_import.h"
 
35
#include "wb_helpers.h"
 
36
 
 
37
using namespace std;
 
38
 
 
39
 
 
40
BEGIN_TEST_DATA_CLASS(wb_mysql_import_dbd4)
 
41
public:
 
42
  GRTManagerTest grtm;
 
43
  WbMysqlImportImpl *module;
 
44
  db_mgmt_RdbmsRef rdbms;
 
45
  DictRef options;
 
46
  GRT *grt;
 
47
  workbench_physical_ModelRef test_import_dbd4(int test_no);
 
48
END_TEST_DATA_CLASS
 
49
 
 
50
 
 
51
TEST_MODULE(wb_mysql_import_dbd4, "WB module: import from DBD4");
 
52
 
 
53
 
 
54
TEST_FUNCTION(1)
 
55
{
 
56
  grt= grtm.get_grt();
 
57
 
 
58
  module= grt->get_native_module<WbMysqlImportImpl>();
 
59
  ensure("WbMysqlImport module initialization", NULL != module);
 
60
 
 
61
  options= DictRef(grt);
 
62
  options.set("gen_fk_names_when_empty", IntegerRef(0));
 
63
}
 
64
 
 
65
 
 
66
#if 0
 
67
workbench_physical_ModelRef Test_object_base<wb_mysql_import_dbd4>::test_import_dbd4(int test_no)
 
68
{
 
69
  ensure("WbMysqlImport module initialization", NULL != module);
 
70
 
 
71
  static const char* TEST_DATA_DIR= "data/modules_grt/wb_mysql_import/dbd4/";
 
72
 
 
73
  /* set filenames & messages based on test no. */
 
74
  ostringstream oss;
 
75
  oss << test_no;
 
76
  string test_message=              "Model (" + oss.str() + ")";
 
77
  string test_model_filename=       TEST_DATA_DIR + oss.str() + ".xml";
 
78
  string test_model_state_filename= TEST_DATA_DIR + oss.str() + "_test.xml";
 
79
  string model_state_filename=      TEST_DATA_DIR + oss.str() + "_res.xml";
 
80
 
 
81
  /* import model */
 
82
  WBTester wbt;
 
83
  wbt.create_new_document();
 
84
  wbt.flush_until(2);
 
85
 
 
86
  ensure_equals("loaded phys model count",
 
87
                wbt.wb->get_document()->physicalModels().count(), 1U);
 
88
 
 
89
  workbench_physical_ModelRef res_model= wbt.wb->get_document()->physicalModels().get(0);
 
90
  module->importDBD4Ex(res_model, test_model_filename, options);
 
91
 
 
92
  db_ColumnRef column(res_model->catalog()->schemata().get(0)->tables().get(0)->columns().get(0));
 
93
 
 
94
  /* serialization */
 
95
  grt->serialize(res_model, model_state_filename);
 
96
 
 
97
  /* unserialization */
 
98
  res_model= workbench_physical_ModelRef::cast_from(grt->unserialize(model_state_filename));
 
99
  workbench_physical_ModelRef test_model= workbench_physical_ModelRef::cast_from(grt->unserialize(test_model_state_filename));
 
100
 
 
101
  /* comparison */
 
102
  grt_ensure_equals(test_message.c_str(), res_model, test_model);
 
103
 
 
104
  return test_model;
 
105
}
 
106
 
 
107
 
 
108
TEST_FUNCTION(10)
 
109
 
110
  test_import_dbd4(0); 
 
111
}
 
112
 
 
113
TEST_FUNCTION(11)
 
114
{
 
115
  test_import_dbd4(1); 
 
116
}
 
117
 
 
118
TEST_FUNCTION(12)
 
119
{
 
120
  test_import_dbd4(2);
 
121
}
 
122
 
 
123
TEST_FUNCTION(13)
 
124
{
 
125
  // this model contains a table with an accented column. should be in UTF8 after imported
 
126
  workbench_physical_ModelRef model= test_import_dbd4(3);
 
127
  
 
128
  ensure("model imported", model.is_valid());
 
129
 
 
130
  db_ColumnRef column(model->catalog()->schemata().get(0)->tables().get(0)->columns().get(0));
 
131
 
 
132
  ensure("imported column name", g_utf8_validate(column->name().c_str(), strlen(column->name().c_str()), NULL) != 0);
 
133
 
 
134
  ensure_equals("imported column name", *column->name(), "reuni\xc3\xb3n");
 
135
}
 
136
#endif
 
137
 
 
138
END_TESTS