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

« back to all changes in this revision

Viewing changes to backend/wbpublic/grt/unit-tests/tree_model_test.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
#include "grt/tree_model.h"
 
23
 
 
24
using namespace grt;
 
25
using namespace bec;
 
26
 
 
27
 
 
28
BEGIN_TEST_DATA_CLASS(be_tree_model)
 
29
public:
 
30
END_TEST_DATA_CLASS;
 
31
 
 
32
 
 
33
 
 
34
TEST_MODULE(be_tree_model, "grt tree model base");
 
35
 
 
36
TEST_FUNCTION(2)
 
37
{
 
38
  NodeId node, node2;
 
39
 
 
40
  ensure("clean node", !node.is_valid());
 
41
 
 
42
  ensure("clean node depth", node.depth()==0);
 
43
 
 
44
  
 
45
  node= NodeId(5);
 
46
  ensure("node(5)", node.is_valid());
 
47
  ensure_equals("node(5).depth()", node.depth(), 1);
 
48
  ensure_equals("node(5)[0]", node[0], 5);
 
49
 
 
50
  node2= node.append(7);
 
51
  ensure_equals("node append", node.depth(), 2);
 
52
  ensure_equals("node append[0]", node[0], 5);
 
53
  ensure_equals("node append[1]", node[1], 7);
 
54
 
 
55
  ensure_equals("node append ret", node2.depth(), 2);
 
56
  ensure_equals("node append ret[0]", node2[0], 5);
 
57
  ensure_equals("node append ret[1]", node2[1], 7);
 
58
  
 
59
  ensure("node compare", node==node2);
 
60
 
 
61
  node2= NodeId(5);
 
62
  ensure("node compare", !(node==node2));
 
63
 
 
64
  node2.append(7);
 
65
  node2.append(11);
 
66
 
 
67
  ensure("node compare", !(node==node2));
 
68
 
 
69
  node= node2;
 
70
  ensure("node assign/compare", node==node2);
 
71
}
 
72
 
 
73
 
 
74
TEST_FUNCTION(3)
 
75
{
 
76
  // serialization
 
77
  NodeId node;
 
78
  std::string s;
 
79
 
 
80
  s= node.repr();
 
81
  ensure_equals("() repr", s, "");
 
82
  ensure("() parse", NodeId(s)==node);
 
83
 
 
84
  node.append(3);
 
85
  s= node.repr();
 
86
  ensure("(3) check", node==NodeId(3));
 
87
  ensure_equals("(3) repr", s, "3");
 
88
  ensure_equals("(3) parse", NodeId(s).repr(), node.repr());
 
89
 
 
90
  node.append(0);
 
91
  s= node.repr();
 
92
  ensure_equals("(3,0) repr", s, "3.0");
 
93
  ensure_equals("(3,0) parse", NodeId(s).repr(), node.repr());
 
94
  
 
95
  node.append(1);
 
96
  s= node.repr();
 
97
  ensure_equals("(3,0,1) repr", s, "3.0.1");
 
98
  ensure_equals("(3,0,1) parse", NodeId(s).repr(), node.repr());
 
99
}
 
100
 
 
101
// test common tree_model methods (get_parent etc)
 
102
 
 
103
 
 
104
 
 
105
END_TESTS