2
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
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.
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
20
#include "tut_stdafx.h"
22
#include "wb_helpers.h"
23
#include "grtdb/db_object_helpers.h"
24
#include "grt_test_utility.h"
25
#include "grtpp_util.h"
26
#include "base/string_utilities.h"
32
BEGIN_TEST_DATA_CLASS(wb_copy_paste)
38
TEST_MODULE(wb_copy_paste, "copy/paste related tests");
41
static bool match_member(const grt::MetaClass::Member *member, const grt::ObjectRef ©, const grt::ObjectRef &source)
43
if (!grt::is_simple_type(member->type.base.type))
49
value1= source.get_member(member->name);
50
value2= copy.get_member(member->name);
52
ensure_equals(member->name, value1.repr(), value2.repr());
58
static void ensure_simple_contents_match(const grt::ObjectRef ©, const grt::ObjectRef &source)
60
grt::MetaClass *mc= copy.get_metaclass();
62
mc->foreach_member(boost::bind(&match_member, _1, copy, source));
66
static void ensure_list_contents_copy(const grt::BaseListRef ©, const grt::BaseListRef &source)
68
ensure("table columns list are not same", copy.valueptr() != source.valueptr());
70
ensure_equals("list size", copy.count(), source.count());
72
for (size_t c= copy.count(), i= 0; i < c; i++)
74
ensure("list content not same", copy[i].valueptr() != source[i].valueptr());
76
ObjectRef copyRef= ObjectRef::cast_from(copy[i]);
77
ObjectRef sourceRef= ObjectRef::cast_from(source[i]);
78
ensure_simple_contents_match(grt::ObjectRef(copyRef), grt::ObjectRef(sourceRef));
87
wb.wb->open_document("data/workbench/all_objects.mwb");
89
ensure_equals("figure count", wb.get_pview()->figures().count(), 6U);
91
workbench_physical_TableFigureRef source, copy;
92
source= workbench_physical_TableFigureRef::cast_from(grt::find_named_object_in_list(wb.get_pview()->figures(), "table1"));
94
ensure("table1", source.is_valid());
96
WBComponent *compo= wb.wb->get_component_handling(source);
97
ensure("table is copiable", compo!=0);
99
grt::CopyContext context(wb.grt);
100
copy= workbench_physical_TableFigureRef::cast_from(compo->clone_object(source, wb.get_pview()->rootLayer(),
103
ensure("copy is valid", copy.is_valid());
105
ensure("both in same view", copy->owner() == source->owner());
106
ensure("both in same layer", copy->layer() == source->layer());
108
ensure("copy is not identical", copy.valueptr() != source.valueptr());
110
ensure("name is not same", copy->table()->name() != source->table()->name());
112
ensure("table is not same", copy->table() != source->table());
114
ensure_list_contents_copy(copy->table()->columns(), source->table()->columns());
116
ensure_list_contents_copy(copy->table()->indices(), source->table()->indices());
122
// create a table with PK and make sure that a copy will contain
123
// proper refs to the copied objects
126
wb.create_new_document();
128
db_mysql_TableRef table;
130
table= db_mysql_TableRef(wb.grt);
131
table->name("person");
133
for (int i= 0; i < 5; i++)
135
db_mysql_ColumnRef column(wb.grt);
137
column->owner(table);
138
column->name(strfmt("col%i", i));
140
column->setParseType("VARCHAR(32)", wb.get_rdbms()->simpleDatatypes());
142
column->setParseType("INT", wb.get_rdbms()->simpleDatatypes());
143
table->columns().insert(column);
146
table->addPrimaryKeyColumn(column);
149
db_mysql_TableRef copy= db_mysql_TableRef::cast_from(grt::copy_object(wb.grt, table));
151
ensure("copy", copy.is_valid());
152
ensure("copy != orig", copy.valueptr() != table.valueptr());
154
ensure_list_contents_copy(table->columns(), copy->columns());
156
ensure("pk exists", copy->primaryKey().is_valid());
157
ensure("primary key copied", copy->primaryKey().valueptr() != table->primaryKey().valueptr());
158
ensure("pk copy points to column copy",
159
copy->primaryKey()->columns()[0].valueptr() != table->primaryKey()->columns()[0].valueptr());
160
ensure("pk points to correct index",
161
copy->indices().get(0).valueptr() == copy->primaryKey().valueptr());
163
ensure_equals("column0", *copy->columns().get(0)->name(), "col0");
164
ensure("column owner", copy->columns().get(0)->owner() == copy);
166
ensure_equals("pk correct", copy->columns().get(0).valueptr(), copy->primaryKey()->columns().get(0)->referencedColumn().valueptr());