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

« back to all changes in this revision

Viewing changes to xtra/pgscript/test/pgsTestGeneratorString.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: pgsTestGeneratorString.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/generators/pgsStringGen.h"
 
14
 
 
15
void pgsTestSuite::test_generator_string(void)
 
16
{
 
17
        const int nb_iterations = 100;
 
18
 
 
19
        // Generate empty strings because of inconsistent arguments
 
20
        {
 
21
                pgsStringGen gen1(0, 0, 10);
 
22
                pgsStringGen gen2(10, 20, 0);
 
23
                // pgsStringGen gen3(-10, -20, 10);
 
24
                // pgsStringGen gen4(10, 20, -10);
 
25
                TS_ASSERT(gen1.random() == wxT(""));
 
26
                TS_ASSERT(gen2.random() == wxT(""));
 
27
                // TS_ASSERT(gen3.random() == wxT(""));
 
28
                // TS_ASSERT(gen4.random() == wxT(""));
 
29
        }
 
30
 
 
31
        // Generate strings with 'a' only
 
32
        {
 
33
                pgsVectorChar chars;
 
34
                chars.Add(wxT('a'));
 
35
                chars.Add(wxT('a'));
 
36
                pgsStringGen gen(2, 2, 3, wxDateTime::GetTimeNow(), chars);
 
37
                for (int i = 0; i < nb_iterations; i++)
 
38
                {
 
39
                        TS_ASSERT(gen.random() == wxT("aa aa aa"));
 
40
                }
 
41
        }
 
42
 
 
43
        // Test strings that are in fact numbers
 
44
        // Test the size of generated strings
 
45
        {
 
46
                pgsVectorChar chars;
 
47
                chars.Add(wxT('1'));
 
48
                chars.Add(wxT('2'));
 
49
                chars.Add(wxT('3'));
 
50
                chars.Add(wxT('4'));
 
51
                pgsStringGen gen(5, 5, 1, wxDateTime::GetTimeNow(), chars);
 
52
                wxString result;
 
53
                for (int i = 0; i < nb_iterations; i++)
 
54
                {
 
55
                        result = gen.random();
 
56
                        long aux_res;
 
57
                        result.ToLong(&aux_res);
 
58
                        TS_ASSERT(MAPM(result.mb_str()) == aux_res && result.Length() == 5);
 
59
                }
 
60
        }
 
61
 
 
62
        // Test the size of generated strings
 
63
        {
 
64
                pgsStringGen gen(10, 11, 3, 123);
 
65
                pgsStringGen comparator(10, 11, 3, 123);
 
66
                wxString result;
 
67
                for (int i = 0; i < nb_iterations; i++)
 
68
                {
 
69
                        result = gen.random();
 
70
                        TS_ASSERT(result == comparator.random());
 
71
                        TS_ASSERT(result.Length() >= 32 && result.Length() <= 35);
 
72
                }
 
73
        }
 
74
 
 
75
        // Test copy constructor
 
76
        {
 
77
                // Create a generator and generate values
 
78
                pgsStringGen gen(10, 11, 3, 123456789L);
 
79
                wxString result, res_cmp;
 
80
                for (int i = 0; i < nb_iterations / 2; i++)
 
81
                {
 
82
                        result = gen.random();
 
83
                }
 
84
                
 
85
                // Copy this generator to a new one
 
86
                // Both generators must generate the same values
 
87
                pgsStringGen comparator(gen);
 
88
                for (int i = nb_iterations / 2; i < nb_iterations; i++)
 
89
                {
 
90
                        result = gen.random();
 
91
                        res_cmp = comparator.random();
 
92
                        TS_ASSERT(result == res_cmp);
 
93
                }
 
94
        }
 
95
 
 
96
        // Test assignment operator
 
97
        {
 
98
                // Create two different generators and generate values
 
99
                pgsStringGen gen(20, 30, 20);
 
100
                pgsStringGen comparator(0, 0, 10);
 
101
                wxString result, res_cmp;
 
102
                for (int i = 0; i < nb_iterations / 2; i++)
 
103
                {
 
104
                        result = gen.random();
 
105
                        res_cmp = comparator.random();
 
106
                }
 
107
                
 
108
                // Copy one of the generators to the other one
 
109
                // Both generators must generate the same values
 
110
                comparator = gen;
 
111
                for (int i = nb_iterations / 2; i < nb_iterations; i++)
 
112
                {
 
113
                        result = gen.random();
 
114
                        res_cmp = comparator.random();
 
115
                        TS_ASSERT(result == res_cmp);
 
116
                }
 
117
        }
 
118
}