source: branches/1.3/examples/objects/curve/curve.cc @ 5675

Last change on this file since 5675 was 5675, checked in by ldelgass, 9 years ago

merge r5673 from trunk (eol-style)

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1#include <iostream>
2#include "RpCurve.h"
3
4size_t indent = 0;
5size_t tabstop = 4;
6
7int test(
8    const char *testname,
9    const char *desc,
10    const char *expected,
11    const char *received)
12{
13    if (strcmp(expected,received) != 0) {
14        printf("Error: %s\n", testname);
15        printf("\t%s\n", desc);
16        printf("\texpected \"%s\"\n",expected);
17        printf("\treceived \"%s\"\n",received);
18        return 1;
19    }
20    return 0;
21}
22
23int curve_0_0 ()
24{
25    const char *desc = "test basic constructor";
26    const char *testname = "curve_0_0";
27
28    const char *expected = "myid";
29    const char *received = NULL;
30
31    Rappture::Curve c(expected);
32    received = c.name();
33
34    return test(testname,desc,expected,received);
35}
36
37int curve_1_0 ()
38{
39    const char *desc = "test generating xml text for curve object";
40    const char *testname = "curve_1_0";
41
42    const char *expected = "<?xml version=\"1.0\"?>\n\
43<run>\n\
44    <curve id=\"myid\">\n\
45        <about>\n\
46            <group>mygroup</group>\n\
47            <label>mylabel</label>\n\
48            <description>mydesc</description>\n\
49            <type>(null)</type>\n\
50        </about>\n\
51        <xaxis>\n\
52            <label>xlabel</label>\n\
53            <description>xdesc</description>\n\
54            <units>xunits</units>\n\
55            <scale>xscale</scale>\n\
56        </xaxis>\n\
57        <yaxis>\n\
58            <label>ylabel</label>\n\
59            <description>ydesc</description>\n\
60            <units>yunits</units>\n\
61            <scale>yscale</scale>\n\
62        </yaxis>\n\
63        <component>\n\
64            <xy>         1         1\n\
65         2         4\n\
66         3         9\n\
67         4        16\n\
68         5        25\n\
69         6        36\n\
70         7        49\n\
71         8        64\n\
72         9        81\n\
73        10       100\n\
74</xy>\n\
75        </component>\n\
76    </curve>\n\
77</run>\n\
78";
79    const char *received = NULL;
80
81    Rappture::Curve *c = NULL;
82    double x[] = {1,2,3,4,5,6,7,8,9,10};
83    double y[] = {1,4,9,16,25,36,49,64,81,100};
84
85    c = new Rappture::Curve("myid","mylabel","mydesc","mygroup");
86
87    c->axis("xaxis","xlabel","xdesc","xunits","xscale",x,10);
88    c->axis("yaxis","ylabel","ydesc","yunits","yscale",y,10);
89
90    Rappture::ClientDataXml xmldata;
91    xmldata.indent = indent;
92    xmldata.tabstop = tabstop;
93    xmldata.retStr = NULL;
94    c->dump(Rappture::RPCONFIG_XML,&xmldata);
95    received = xmldata.retStr;
96
97    return test(testname,desc,expected,received);
98}
99
100int main()
101{
102    curve_0_0 ();
103    curve_1_0 ();
104    return 0;
105}
Note: See TracBrowser for help on using the repository browser.