~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to xtra/pgscript/test/pgsTestExpressionRecord.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgScript - PostgreSQL Tools
 
4
// RCS-ID:      $Id: pgsTestExpressionRecord.cpp 7758 2009-03-26 20:49:59Z dpage $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
 
7
//
 
8
//////////////////////////////////////////////////////////////////////////
 
9
 
 
10
 
 
11
#include "pgsTestSuite.h"
 
12
 
 
13
#include "pgscript/expressions/pgsAssign.h"
 
14
#include "pgscript/expressions/pgsAssignToRecord.h"
 
15
#include "pgscript/expressions/pgsDifferent.h"
 
16
#include "pgscript/expressions/pgsIdent.h"
 
17
#include "pgscript/expressions/pgsLower.h"
 
18
#include "pgscript/expressions/pgsRemoveLine.h"
 
19
#include "pgscript/objects/pgsNumber.h"
 
20
#include "pgscript/objects/pgsString.h"
 
21
#include "pgscript/statements/pgsDeclareRecordStmt.h"
 
22
#include "pgscript/statements/pgsExpressionStmt.h"
 
23
#include "pgscript/statements/pgsStmtList.h"
 
24
 
 
25
void pgsTestSuite::test_expression_record(void)
 
26
{
 
27
        pgsVarMap vars;
 
28
 
 
29
        pgsStmtList * SL1 = 0;
 
30
 
 
31
        wxArrayString columns;
 
32
        SL1 = pnew pgsStmtList(pgsTestClass::get_cout());
 
33
 
 
34
        {
 
35
                columns.Add(wxT("a"));
 
36
                columns.Add(wxT("b"));
 
37
                columns.Add(wxT("c"));
 
38
                columns.Add(wxT("d"));
 
39
        }
 
40
 
 
41
        // r := { a, b, c, d }
 
42
        {
 
43
                pgsStmt * S = 0;
 
44
                S = pnew pgsDeclareRecordStmt(wxT("r"), columns);
 
45
                SL1->insert_back(S);
 
46
        }
 
47
 
 
48
        // r[2][a] := 5
 
49
        {
 
50
                pgsStmt * S = 0;
 
51
                S = pnew pgsExpressionStmt(pnew pgsAssignToRecord(wxT("r"),
 
52
                                pnew pgsNumber(wxT("2")), pnew pgsString(wxT("a")),
 
53
                                pnew pgsNumber(wxT("5"))));
 
54
                SL1->insert_back(S);
 
55
        }
 
56
 
 
57
        // r[1][b] := "abc"
 
58
        {
 
59
                pgsStmt * S = 0;
 
60
                S = pnew pgsExpressionStmt(pnew pgsAssignToRecord(wxT("r"),
 
61
                                pnew pgsNumber(wxT("1")), pnew pgsString(wxT("b")),
 
62
                                pnew pgsString(wxT("abc"))));
 
63
                SL1->insert_back(S);
 
64
        }
 
65
 
 
66
        // r[0][0] := 1
 
67
        {
 
68
                pgsStmt * S = 0;
 
69
                S = pnew pgsExpressionStmt(pnew pgsAssignToRecord(wxT("r"),
 
70
                                pnew pgsNumber(wxT("0")), pnew pgsNumber(wxT("0")),
 
71
                                pnew pgsNumber(wxT("1"))));
 
72
                SL1->insert_back(S);
 
73
        }
 
74
 
 
75
        // w := r
 
76
        {
 
77
                pgsStmt * S = 0;
 
78
                S = pnew pgsExpressionStmt(pnew pgsAssign(wxT("w"),
 
79
                                pnew pgsIdent(wxT("r"))));
 
80
                SL1->insert_back(S);
 
81
        }
 
82
 
 
83
        // p = (r != w)
 
84
        {
 
85
                pgsStmt * S = 0;
 
86
                S = pnew pgsExpressionStmt(pnew pgsAssign(wxT("p"),
 
87
                                pnew pgsDifferent(pnew pgsIdent(wxT("r")),
 
88
                                pnew pgsIdent(wxT("w")))));
 
89
                SL1->insert_back(S);
 
90
        }
 
91
 
 
92
        // r.remove_line(1)
 
93
        {
 
94
                pgsStmt * S = 0;
 
95
                S = pnew pgsExpressionStmt(pnew pgsRemoveLine(wxT("r"),
 
96
                                pnew pgsNumber(wxT("1"))));
 
97
                TS_ASSERT(pgsRemoveLine(wxT("r"), pnew pgsNumber(wxT("1")))
 
98
                                .value() == wxT("RMLINE(r[1])"));
 
99
                SL1->insert_back(S);
 
100
        }
 
101
 
 
102
        // q = (r != w)
 
103
        {
 
104
                pgsStmt * S = 0;
 
105
                S = pnew pgsExpressionStmt(pnew pgsAssign(wxT("q"),
 
106
                                pnew pgsDifferent(pnew pgsIdent(wxT("r")),
 
107
                                pnew pgsIdent(wxT("w")))));
 
108
                SL1->insert_back(S);
 
109
        }
 
110
 
 
111
        // o = (r < w)
 
112
        {
 
113
                pgsStmt * S = 0;
 
114
                S = pnew pgsExpressionStmt(pnew pgsAssign(wxT("o"),
 
115
                                pnew pgsLower(pnew pgsIdent(wxT("r")),
 
116
                                pnew pgsIdent(wxT("w")))));
 
117
                SL1->insert_back(S);
 
118
        }
 
119
 
 
120
        SL1->eval(vars);
 
121
 
 
122
        // Test symbol table at the end of the execution
 
123
        TS_ASSERT(vars[wxT("p")]->value() == wxT("0"));
 
124
        TS_ASSERT(vars[wxT("q")]->value() == wxT("1"));
 
125
        TS_ASSERT(vars[wxT("o")]->value() == wxT("1"));
 
126
 
 
127
        pdelete(SL1);
 
128
}