File: test2.C

package info (click to toggle)
paraview 4.1.0%2Bdfsg%2B1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 278,136 kB
  • ctags: 340,527
  • sloc: cpp: 2,314,053; ansic: 817,139; python: 245,770; xml: 68,996; tcl: 48,285; fortran: 39,116; yacc: 5,713; java: 3,827; perl: 3,108; sh: 2,045; lex: 1,809; makefile: 935; asm: 471; pascal: 228
file content (566 lines) | stat: -rw-r--r-- 15,060 bytes parent folder | download | duplicates (4)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
/*****************************************************************************
*
* Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400124
* All rights reserved.
*
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

#include <PlotList.h>
#include <Observer.h>
#include <BufferConnection.h>

#include <TestUtil.h>

#define VERBOSE
#define N_TESTS 2

// Prototypes
bool Run_Test1(bool verbose, int *subtest, int *nsubtests);
bool Run_Test2(bool verbose, int *subtest, int *nsubtests);

// *******************************************************************
// Function: main
//
// Purpose:
//   The main function for this test program. It executes the test
//   cases.
//
// Programmer: Brad Whitlock
// Creation:   Thu Aug 10 15:34:38 PST 2000
//
// Modifications:
//   
// *******************************************************************

int
main(int argc, char *argv[])
{
    int      subtest, nsubtests;
    bool     test[N_TESTS];
    TestUtil util(argc, argv, "Tests Plot and PlotList classes");

    // Test the Plot class.
    test[0] = Run_Test1(util.verbose, &subtest, &nsubtests);
    util.PrintTestResult(1, subtest, nsubtests, test[0]);

    // Test the Plot class.
    test[1] = Run_Test2(util.verbose, &subtest, &nsubtests);
    util.PrintTestResult(2, subtest, nsubtests, test[1]);
    
    return util.PassFail(test, N_TESTS);
}

///////////////////////////////////////////////////////////////////////////
/// Test 1 - Test the Plot class.
///
/// Notes:
///    This test is designed to test various methods and operators in the
///    Plot class.
///
///////////////////////////////////////////////////////////////////////////
#ifdef VERBOSE
ostream &
operator << (ostream &os, const Plot &p)
{
    const char *names[] = {
       "BLOCK=0", "BOUNDARY=1", "CONTOUR=2", "CURVE=3", "FILLED_BOUNDARY=4",
       "LABEL=5", "MESH=6", "PICK=7", "PSEUDOCOLOR=8", "REFLINE=9", "SURFACE=10",
       "VECTOR=11"
    };

    os << "{plotType=" << names[p.GetPlotType()];
    os << ", activeFlag=" << p.GetActiveFlag();
    os << ", hiddenFlag=" << p.GetHiddenFlag();
    os << ", plotVar=" << p.GetPlotVar();
    os << "}";

    return os;
}
#endif

// *******************************************************************
// Function: Run_Test1
//
// Purpose:
//   Tests operations for the Plot class.
//
// Arguments:
//   verbose   : Whether or not to do lots of output.
//   subtest   : A return code to indicate the last subtest to be
//               executed.
//   nsubtests : The number of subtests.
//
// Notes:      
//
// Programmer: Brad Whitlock
// Creation:   Thu Aug 10 16:09:30 PST 2000
//
// Modifications:
//   
// *******************************************************************

bool
Run_Test1(bool verbose, int *subtest, int *nsubtests)
{
    // We have 7 subtests
    *nsubtests = 7;

#ifdef VERBOSE
    if(verbose)
    {
        cout << "=================================================" << endl;
        cout << "Running Test 1" << endl;
        cout << "=================================================" << endl;
    }
#endif

    // Create a plot
    Plot p1;

    // Test set/get PlotType
    *subtest = 1;
    p1.SetPlotType(Plot::BLOCK);
    if(p1.GetPlotType() != Plot::BLOCK)
        return false;

    // Test set/get ActiveFlag
    *subtest = 2;
    p1.SetActiveFlag(false);
    if(p1.GetActiveFlag() != false)
        return false;

    // Test set/get HiddenFlag
    *subtest = 3;
    p1.SetHiddenFlag(true);
    if(p1.GetHiddenFlag() != true)
        return false;

    // Test set/get PlotVar
    *subtest = 4;
    p1.SetPlotVar("density");
    if(p1.GetPlotVar() != std::string("density"))
        return false;

    // Create another plot
    Plot p2;

    // Test the assignment operator
    *subtest = 5;
    p2 = p1;
    if(p1 != p2)
        return false;

    // Test the copy constructor
    *subtest = 6;
    Plot p3(p1);
    if(p1 != p3)
        return false;

    // Try writing and reading a Plot object
    *subtest = 7;
    BufferConnection buf;
    bool retval = true;
    for(int i = 0; (i < 4) && retval; ++i)
    {
        Plot writer, reader;

        if(i >= 0)
            writer.SetPlotType(Plot::PSEUDOCOLOR);
        if(i >= 1)
            writer.SetActiveFlag(true);
        if(i >= 2)
            writer.SetHiddenFlag(true);
        if(i >= 3)
            writer.SetPlotVar(std::string("p"));

        // Write the Plot to the connection
        writer.Write(buf);

        // Read the Plot from the connection
        reader.Read(buf);

        // See if the Plots are equal
        retval = (reader == writer);
#ifdef VERBOSE
        // Write the plot to stdout
        if(verbose)
            cout << endl << "Writer:" << writer << endl << "Reader:"
                 << reader << endl << endl;
#endif
    }

    return retval;
}

///////////////////////////////////////////////////////////////////////////
/// Test 2 - Test the PlotList class.
///
/// Notes:
///    This test is designed to test various methods and operators in the
///    PlotList class.
///
///////////////////////////////////////////////////////////////////////////

// *******************************************************************
// Class: PlotListPrinter
//
// Purpose:
//   This observer class prints out the fields that have changed in a
//   PlotList.
//
// Notes:      
//
// Programmer: Brad Whitlock
// Creation:   Fri Aug 11 13:31:16 PST 2000
//
// Modifications:
//   
// *******************************************************************

class PlotListPrinter : public Observer
{
public:
    PlotListPrinter(PlotList *plots) : Observer((Subject *)plots)
    {
        // nothing much
    }

    ~PlotListPrinter()
    {
        // nothing here
    }

    virtual void Update(Subject *)
    {
        PlotList *plots = (PlotList *)subject;
        const char *names[] = {
            "BLOCK=0", "BOUNDARY=1", "CONTOUR=2", "CURVE=3", "FILLED_BOUNDARY=4",
            "LABEL=5", "MESH=6", "PICK=7", "PSEUDOCOLOR=8", "REFLINE=9", "SURFACE=10",
            "VECTOR=11"
        };

        // There is only one attribute in the PlotList class and it is
        // the plot list.

        cout << "{";
        for(int i = 0; i < plots->GetNumPlots(); ++i)
        {
            Plot &p = plots->GetPlot(i);
            cout << "{type=" << names[(int)p.GetPlotType()] <<
                    ", active=" << p.GetActiveFlag() <<
                    ", hidden=" << p.GetHiddenFlag() <<
                    ", var=" << p.GetPlotVar() << "}, ";
        }
        cout << "}" << endl;
    }
};

// *******************************************************************
// Function: operator << (ostream &os, const PlotList &p)
//
// Purpose:
//   Writes a PlotList to an ostream.
//
// Notes:      
//
// Programmer: Brad Whitlock
// Creation:   Fri Aug 11 13:30:43 PST 2000
//
// Modifications:
//   
// *******************************************************************

ostream &
operator << (ostream &os, const PlotList &p)
{
    os << "{";
    for(int i = 0; i < p.GetNumPlots(); ++i)
        os << "plot[" << i << "]=" << p[i] << ", ";
    os << "}";

    return os;
}

// *******************************************************************
// Function: Run_Test2
//
// Purpose:
//   This function runs this program's test case #2 which tests the 
//   PlotList class.
//
// Arguments:
//   verbose   : Whether or not to do lots of output.
//   subtest   : A return code to indicate the last subtest to be
//               executed.
//   nsubtests : The number of subtests.
//
// Programmer: Brad Whitlock
// Creation:   Fri Aug 11 13:30:06 PST 2000
//
// Modifications:
//   
// *******************************************************************

bool
Run_Test2(bool verbose, int *subtest, int *nsubtests)
{
    // We have 11 subtests
    *nsubtests = 11;

#ifdef VERBOSE
    if(verbose)
    {
        cout << "=================================================" << endl;
        cout << "Running Test 2" << endl;
        cout << "=================================================" << endl;
    }
#endif

    // Create a plot
    Plot plot1;
    plot1.SetPlotType(Plot::FILLED_BOUNDARY);
    plot1.SetActiveFlag(true);
    plot1.SetHiddenFlag(true);
    plot1.SetPlotVar("rho");

    // Create another plot
    Plot plot2;
    plot2.SetPlotType(Plot::CONTOUR);
    plot2.SetActiveFlag(true);
    plot2.SetHiddenFlag(false);
    plot2.SetPlotVar("density");

    // Create another plot
    Plot plot3;
    plot3.SetPlotType(Plot::PSEUDOCOLOR);
    plot3.SetActiveFlag(false);
    plot3.SetHiddenFlag(true);
    plot3.SetPlotVar("pressure");

    // Create a plot list
    PlotList p1;

    // Test adding plots and the [] operator.
    *subtest = 1;
    p1.AddPlot(plot1);
    if(p1[0] != plot1)
        return false;

    // Test GetNumPlots
    *subtest = 2;
    if(p1.GetNumPlots() != 1)
        return false;

    // Test the copy constructor and the == operator
    *subtest = 3;
    PlotList p2(p1);
#ifdef VERBOSE
    if(verbose)
        cout << "p1=" << p1 << endl << "p2=" << p2 << endl;
#endif
    if(p1 != p2)
        return false;

    // Test ClearPlots
    *subtest = 4;
    p1.AddPlot(plot2);
    p1.ClearPlots();
    if(p1.GetNumPlots() != 0)
        return false;

    // Test RemovePlot
    *subtest = 5;
    PlotList p3;
    p3.AddPlot(plot1);
    p3.AddPlot(plot2);
    p3.AddPlot(plot3);
    PlotList p4(p3);
#ifdef VERBOSE
    if(verbose)
        cout << endl << "p3=" << p3 << endl << "p4=" << p4 << endl;
#endif
    p3.RemovePlot(1); // Remove the 2nd plot from both
    p4.RemovePlot(1);
#ifdef VERBOSE
    if(verbose)
        cout << endl << "p3=" << p3 << endl << "p4=" << p4 << endl;
#endif
    if(p3 != p4)
        return false;

    // Test GetPlot
    *subtest = 6;
    PlotList p5;
    p5.AddPlot(plot1);
    // Set the plot to plot3's attributes.
    p5.GetPlot(0).SetPlotType(Plot::PSEUDOCOLOR);
    p5.GetPlot(0).SetActiveFlag(false);
    p5.GetPlot(0).SetHiddenFlag(true);
    p5.GetPlot(0).SetPlotVar("pressure");
#ifdef VERBOSE
    if(verbose)
        cout << endl << "p5[0]=" << p5.GetPlot(0) << ", plot3="
             << plot3 << endl;
#endif
    if(p5.GetPlot(0) != plot3)
        return false;

    // Test the [] operator
    *subtest = 7;
    PlotList p6;
    p6.AddPlot(plot1);
    // Set the plot to plot3's attributes.
    p6[0].SetPlotType(Plot::PSEUDOCOLOR);
    p6[0].SetActiveFlag(false);
    p6[0].SetHiddenFlag(true);
    p6[0].SetPlotVar("pressure");
#ifdef VERBOSE
    if(verbose)
        cout << endl << "p6[0]=" << p6.GetPlot(0) << ", plot3="
             << plot3 << endl;
#endif
    if(p6[0] != plot3)
        return false;

    // Test the assignment operator
    *subtest = 8;
    PlotList p7, p8;
    p7.AddPlot(plot1);
    p7.AddPlot(plot2);
    p8 = p7;
    if(verbose)
        cout << endl << "p7=" << p7 << endl << "p8=" << p8 << endl;
    if(p7 != p8)
       return false;

    // Test writing and reading a PlotList
    *subtest = 9;
    bool retval = true;
    BufferConnection buf;
#ifdef VERBOSE
    if(verbose)
        cout << endl << "Testing read/write of PlotList" << endl;
#endif
    for(int i = 0; (i < 3) && retval; ++i)
    {
        PlotList writer;

        plot1.UnSelectAll();
        plot2.UnSelectAll();
        plot3.UnSelectAll();

        if(i >= 0)
           writer.AddPlot(plot1);
        if(i >= 1)
           writer.AddPlot(plot2);
        if(i >= 2)
           writer.AddPlot(plot3);

        // Write to the vuffer
        writer.Write(buf);

        // Read from the buffer.
        PlotList reader;
        reader.Read(buf);

#ifdef VERBOSE
        if(verbose)
        {
            PlotListPrinter *TObserver = new PlotListPrinter(&reader);
            reader.Notify();
            delete TObserver;
        }
#endif

        // See if they were equal.
        retval = (writer == reader);
    }
    if(!retval)
        return false;

    // Test sending a PlotList that has had a plot removed.
    *subtest = 10;
#ifdef VERBOSE
    if(verbose)
        cout << endl << "Testing read/write of PlotList" << endl;
#endif
    PlotList p9;
    p9.AddPlot(plot1);
    p9.AddPlot(plot2);
    PlotList p10(p9);
    // Remove plot 0 from p9.
    p9.RemovePlot(0);

    p9.Write(buf);
    p10.Read(buf);
#ifdef VERBOSE
    if(verbose)
    {
        PlotListPrinter *TObserver = new PlotListPrinter(&p10);
        p10.Notify();
        delete TObserver;
    }
#endif
    if(p9 != p10)
        return false;

    // Test sending a PlotList that has been emptied.
    *subtest = 11;
#ifdef VERBOSE
    if(verbose)
        cout << endl << "Testing read/write of PlotList" << endl;
#endif
    PlotList p11;
    p11.AddPlot(plot1);
    p11.AddPlot(plot2);
    PlotList p12(p11);
    // Remove all plots from p11 and write it
    p11.ClearPlots();
    p11.Write(buf);

    // Read an empty PlotList into p12.
    p12.Read(buf);
#ifdef VERBOSE
    if(verbose)
    {
        PlotListPrinter *TObserver = new PlotListPrinter(&p12);
        p12.Notify();
        delete TObserver;
    }
#endif
    if(p12.GetNumPlots() != 0)
        return false;

    return true;
}