MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
testConfigValues.cpp
1 /*
2  Copyright (C) 2004-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the 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 02110-1301 USA
17 */
18 
19 #include <ConfigValues.hpp>
20 #include <NdbOut.hpp>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #define CF_NODES 1
25 #define CF_LOG_PAGES 2
26 #define CF_MEM_PAGES 3
27 #define CF_START_TO 4
28 #define CF_STOP_TO 5
29 
30 void print(Uint32 i, ConfigValues::ConstIterator & cf){
31  ndbout_c("---");
32  for(Uint32 j = 2; j<=7; j++){
33  switch(cf.getTypeOf(j)){
34  case ConfigValues::IntType:
35  ndbout_c("Node %d : CFG(%d) : %d",
36  i, j, cf.get(j, 999));
37  break;
38  case ConfigValues::Int64Type:
39  ndbout_c("Node %d : CFG(%d) : %lld (64)",
40  i, j, cf.get64(j, 999));
41  break;
42  case ConfigValues::StringType:
43  ndbout_c("Node %d : CFG(%d) : %s",
44  i, j, cf.get(j, "<NOT FOUND>"));
45  break;
46  default:
47  ndbout_c("Node %d : CFG(%d) : TYPE: %d",
48  i, j, cf.getTypeOf(j));
49  }
50  }
51 }
52 
53 void print(Uint32 i, ConfigValues & _cf){
55  print(i, cf);
56 }
57 
58 void
59 print(ConfigValues & _cf){
61  Uint32 i = 0;
62  while(cf.openSection(CF_NODES, i)){
63  print(i, cf);
64  cf.closeSection();
65  i++;
66  }
67 }
68 
69 inline
70 void
71 require(bool b){
72  if(!b)
73  abort();
74 }
75 
76 int
77 main(void){
78 
79  {
80  ConfigValuesFactory cvf(10, 20);
81  cvf.openSection(1, 0);
82  cvf.put(2, 12);
83  cvf.put64(3, 13);
84  cvf.put(4, 14);
85  cvf.put64(5, 15);
86  cvf.put(6, "Keso");
87  cvf.put(7, "Kent");
88  cvf.closeSection();
89 
90  cvf.openSection(1, 1);
91  cvf.put(2, 22);
92  cvf.put64(3, 23);
93  cvf.put(4, 24);
94  cvf.put64(5, 25);
95  cvf.put(6, "Kalle");
96  cvf.put(7, "Anka");
97  cvf.closeSection();
98 
99  ndbout_c("-- print --");
100  print(* cvf.m_cfg);
101 
102  cvf.shrink();
103  ndbout_c("shrink\n-- print --");
104  print(* cvf.m_cfg);
105  cvf.expand(10, 10);
106  ndbout_c("expand\n-- print --");
107  print(* cvf.m_cfg);
108 
109  ndbout_c("packed size: %d", cvf.m_cfg->getPackedSize());
110 
111  ConfigValues::ConstIterator iter(* cvf.m_cfg);
112  iter.openSection(CF_NODES, 0);
113  ConfigValues * cfg2 = ConfigValuesFactory::extractCurrentSection(iter);
114  print(99, * cfg2);
115 
116  cvf.shrink();
117  ndbout_c("packed size: %d", cfg2->getPackedSize());
118 
119  UtilBuffer buf;
120  Uint32 l1 = cvf.m_cfg->pack(buf);
121  Uint32 l2 = cvf.m_cfg->getPackedSize();
122  require(l1 == l2);
123 
124  ConfigValuesFactory cvf2;
125  require(cvf2.unpack(buf));
126  UtilBuffer buf2;
127  cvf2.shrink();
128  Uint32 l3 = cvf2.m_cfg->pack(buf2);
129  require(l1 == l3);
130 
131  ndbout_c("unpack\n-- print --");
132  print(* cvf2.m_cfg);
133 
134  cfg2->~ConfigValues();;
135  cvf.m_cfg->~ConfigValues();
136  free(cfg2);
137  free(cvf.m_cfg);
138  }
139  return 0;
140 }