summaryrefslogtreecommitdiff
path: root/storage/ndb/test/newtonapi/basic_test/common.cpp
blob: 28ae60d2cd6db6a512681b1824e5c7af32c6c28b (plain)
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
/* Copyright (c) 2003-2005 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


#include "common.hpp"

NdbOut &
operator << (NdbOut & out, const Employee_t & emp){
  out << emp.EmpNo << " \"" << emp.FirstName << "\" \"" 
      << emp.LastName << "\"";
  return out;
}

bool
operator==(const Employee_t & e1, const Employee_t & e2){
  if(e1.EmpNo != e2.EmpNo)
    return false;
  if(strcmp(e1.FirstName, e2.FirstName) != 0)
    return false;
  return strcmp(e1.LastName, e2.LastName) == 0;
}

void
Alter(Employee_t & emp){
  static int updown = 0;
  if(updown == 0){
    for(int i = 0; i<strlen(emp.FirstName); i++)
      toupper(emp.FirstName[i]);
    
    for(int i = 0; i<strlen(emp.LastName); i++)
      toupper(emp.LastName[i]);
  } else {
    for(int i = 0; i<strlen(emp.FirstName); i++)
      tolower(emp.FirstName[i]);
    
    for(int i = 0; i<strlen(emp.LastName); i++)
      tolower(emp.LastName[i]);
  }
  updown = 1 - updown;
}

void
CompareRows(Employee_t * data1,
	    int rows,  
	    Employee_t * data2){
  for(int i = 0; i<rows; i++){
    if(!(data1[i] == data2[i])){
      ndbout << data1[i] << endl
	     << data2[i] << endl;
    }
  }
}

void
AlterRows(Employee_t * data1, int rows){
  for(int i = 0; i<rows; i++){
    Alter(data1[i]);
  }
}

inline
NdbOut &
operator << (NdbOut & out, const Address_t & adr){
  out << adr.EmpNo << " \"" << adr.StreetName << "\" " 
      << adr.StreetNo << " \"" << adr.City << "\"";
  return out;
}

inline
bool
operator==(const Address_t & a1, const Address_t & a2){
  if(a1.EmpNo != a2.EmpNo)
    return false;
  if(a1.StreetNo != a2.StreetNo)
    return false;
  if(strcmp(a1.StreetName, a2.StreetName) != 0)
    return false;
  return strcmp(a1.City, a2.City) == 0;
}

inline
void
Alter(Address_t & emp){
  static int updown = 0;
  if(updown == 0){
    for(int i = 0; i<strlen(emp.StreetName); i++)
      toupper(emp.StreetName[i]);
    
    for(int i = 0; i<strlen(emp.City); i++)
      toupper(emp.City[i]);
  } else {
    for(int i = 0; i<strlen(emp.StreetName); i++)
      tolower(emp.StreetName[i]);
    
    for(int i = 0; i<strlen(emp.City); i++)
      tolower(emp.City[i]);
  }
  emp.StreetNo *= emp.EmpNo;
  updown = 1 - updown;
}

void
CompareRows(Address_t * data1,
	    int rows,  
	    Address_t * data2){
  for(int i = 0; i<rows; i++){
    if(!(data1[i] == data2[i])){
      ndbout << data1[i] << endl
	     << data2[i] << endl;
    }
  }
}

void
AlterRows(Address_t * data1, int rows){
  for(int i = 0; i<rows; i++){
    Alter(data1[i]);
  }
}