1
//////////////////////////////////////////////////////////////////////////
3
// pgScript - PostgreSQL Tools
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
6
// This software is released under the PostgreSQL Licence
8
//////////////////////////////////////////////////////////////////////////
11
#include "pgsTestSuite.h"
13
#include "pgscript/exceptions/pgsException.h"
14
#include "pgscript/generators/pgsIntegerGen.h"
15
#include "pgscript/generators/pgsStringGen.h"
16
#include "pgscript/objects/pgsGenerator.h"
17
#include "pgscript/objects/pgsNumber.h"
18
#include "pgscript/objects/pgsRecord.h"
19
#include "pgscript/objects/pgsString.h"
21
void pgsTestSuite::test_operator_string(void)
23
// From a string with a string
25
// [1] Create variables
26
pgsVariable * var0 = 0;
27
var0 = pnew pgsString(wxT("abc"));
28
pgsVariable * var1 = 0;
29
var1 = pnew pgsString(wxT("ABC"));
32
TS_ASSERT((*var0 + *var1)->value() == wxT("abcABC"));
40
catch (const pgsException &)
51
catch (const pgsException &)
62
catch (const pgsException &)
73
catch (const pgsException &)
79
TS_ASSERT((*var0 == *var1)->value() == wxT("0"));
82
TS_ASSERT((*var0 != *var1)->value() == wxT("1"));
85
TS_ASSERT((*var0 < *var1)->value() == wxT("0"));
88
TS_ASSERT((*var0 > *var1)->value() == wxT("1"));
90
// [13] Lower or equal
91
TS_ASSERT((*var0 <= *var1)->value() == wxT("0"));
93
// [14] Greater or equal
94
TS_ASSERT((*var0 >= *var1)->value() == wxT("1"));
97
TS_ASSERT((!(*var0))->value() == wxT(""));
98
pgsOperand op(pnew pgsString(wxT("")));
99
TS_ASSERT((!(*op))->value() == wxT("1"));
102
TS_ASSERT((*var0 &= *var1)->value() == wxT("1"));
105
TS_ASSERT(var0->pgs_is_true() == true);
106
TS_ASSERT((!(*var0))->pgs_is_true() == false);
108
// [18] Delete variables
113
// From a string with a number
115
// [1] Create variables
116
pgsVariable * var0 = 0;
117
var0 = pnew pgsString(wxT("abc"));
118
pgsVariable * var1 = 0;
119
var1 = pnew pgsNumber(wxT("123"));
127
catch (const pgsException &)
138
catch (const pgsException &)
143
// [4] Multiplication
149
catch (const pgsException &)
160
catch (const pgsException &)
171
catch (const pgsException &)
182
catch (const pgsException &)
193
catch (const pgsException &)
204
catch (const pgsException &)
215
catch (const pgsException &)
220
// [13] Lower or equal
226
catch (const pgsException &)
231
// [14] Greater or equal
237
catch (const pgsException &)
243
TS_ASSERT((!(*var0))->value() == wxT(""));
251
catch (const pgsException &)
257
TS_ASSERT(var0->pgs_is_true() == true);
258
TS_ASSERT((!(*var0))->pgs_is_true() == false);
260
// [18] Delete variables
265
// From a string with a record
267
// [1] Create variables
268
pgsVariable * var0 = 0;
269
var0 = pnew pgsString(wxT("abc"));
271
rec = pnew pgsRecord(1);
272
rec->insert(0, 0, pnew pgsString(wxT("ABC")));
273
pgsVariable * var1 = 0;
282
catch (const pgsException &)
293
catch (const pgsException &)
298
// [4] Multiplication
304
catch (const pgsException &)
315
catch (const pgsException &)
326
catch (const pgsException &)
337
catch (const pgsException &)
348
catch (const pgsException &)
359
catch (const pgsException &)
370
catch (const pgsException &)
375
// [13] Lower or equal
381
catch (const pgsException &)
386
// [14] Greater or equal
392
catch (const pgsException &)
398
TS_ASSERT((!(*var0))->value() == wxT(""));
406
catch (const pgsException &)
412
TS_ASSERT(var0->pgs_is_true() == true);
413
TS_ASSERT((!(*var0))->pgs_is_true() == false);
415
// [18] Delete variables
420
// From a string with a string generator
422
// [1] Create variables
423
pgsVariable * var0 = 0;
424
var0 = pnew pgsString(wxT("abc"));
425
pgsStringGen * gen = 0;
426
gen = pnew pgsStringGen(10, 20);
427
pgsVariable * var1 = 0;
428
var1 = pnew pgsGenerator(pgsVariable::pgsTString, gen);
431
TS_ASSERT((*var0 + *var1)->value().StartsWith(wxT("abc")));
439
catch (const pgsException &)
444
// [4] Multiplication
450
catch (const pgsException &)
461
catch (const pgsException &)
472
catch (const pgsException &)
478
TS_ASSERT((*var0 == *var1)->value() == wxT("0"));
481
TS_ASSERT((*var0 != *var1)->value() == wxT("1"));
488
catch (const pgsException &)
498
catch (const pgsException &)
503
// [13] Lower or equal
508
catch (const pgsException &)
513
// [14] Greater or equal
518
catch (const pgsException &)
524
TS_ASSERT((!(*var0))->value() == wxT(""));
527
TS_ASSERT((*var0 &= *var1)->value() == wxT("0"));
530
TS_ASSERT(var0->pgs_is_true() == true);
531
TS_ASSERT((!(*var0))->pgs_is_true() == false);
533
// [18] Delete variables
538
// From a string with an integer generator
540
// [1] Create variables
541
pgsVariable * var0 = 0;
542
var0 = pnew pgsString(wxT("abc"));
543
pgsIntegerGen * gen = 0;
544
gen = pnew pgsIntegerGen(10, 10);
545
pgsVariable * var1 = 0;
546
var1 = pnew pgsGenerator(pgsVariable::pgsTInt, gen);
554
catch (const pgsException &)
565
catch (const pgsException &)
570
// [4] Multiplication
576
catch (const pgsException &)
587
catch (const pgsException &)
598
catch (const pgsException &)
609
catch (const pgsException &)
620
catch (const pgsException &)
631
catch (const pgsException &)
642
catch (const pgsException &)
647
// [13] Lower or equal
653
catch (const pgsException &)
658
// [14] Greater or equal
664
catch (const pgsException &)
670
TS_ASSERT((!(*var0))->value() == wxT(""));
678
catch (const pgsException &)
684
TS_ASSERT(var0->pgs_is_true() == true);
685
TS_ASSERT((!(*var0))->pgs_is_true() == false);
687
// [18] Delete variables