1 | #include <iostream> |
---|
2 | #include "RpPlot.h" |
---|
3 | |
---|
4 | size_t indent = 0; |
---|
5 | size_t tabstop = 4; |
---|
6 | |
---|
7 | int 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 | |
---|
23 | int plot_0_0 () |
---|
24 | { |
---|
25 | const char *desc = "test basic plot object constructor"; |
---|
26 | const char *testname = "plot_0_0"; |
---|
27 | |
---|
28 | const char *expected = "run"; |
---|
29 | const char *received = NULL; |
---|
30 | |
---|
31 | Rappture::Plot p; |
---|
32 | received = p.path(); |
---|
33 | |
---|
34 | return test(testname,desc,expected,received); |
---|
35 | } |
---|
36 | |
---|
37 | int plot_1_0 () |
---|
38 | { |
---|
39 | const char *desc = "test generating xml text for single curve"; |
---|
40 | const char *testname = "plot_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>plotlabel</group>\n\ |
---|
47 | <label>plotlabel</label>\n\ |
---|
48 | <description>describe plot here</description>\n\ |
---|
49 | <type>(null)</type>\n\ |
---|
50 | </about>\n\ |
---|
51 | <xaxis>\n\ |
---|
52 | <label>Voltage</label>\n\ |
---|
53 | <description>Voltage along the Gate</description>\n\ |
---|
54 | <units>Volt</units>\n\ |
---|
55 | <scale>linear</scale>\n\ |
---|
56 | </xaxis>\n\ |
---|
57 | <yaxis>\n\ |
---|
58 | <label>Current</label>\n\ |
---|
59 | <description>Current along the Drain</description>\n\ |
---|
60 | <units>Amp</units>\n\ |
---|
61 | <scale>log</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::Plot p; |
---|
82 | size_t npts = 10; |
---|
83 | double x[] = {1,2,3,4,5,6,7,8,9,10}; |
---|
84 | double y[] = {1,4,9,16,25,36,49,64,81,100}; |
---|
85 | |
---|
86 | p.add(npts, x, y, NULL, "myid"); |
---|
87 | |
---|
88 | p.propstr("label","plotlabel"); |
---|
89 | p.propstr("desc","describe plot here"); |
---|
90 | p.propstr("xlabel","Voltage"); |
---|
91 | p.propstr("xdesc","Voltage along the Gate"); |
---|
92 | p.propstr("xunits","Volt"); |
---|
93 | p.propstr("xscale","linear"); |
---|
94 | p.propstr("ylabel","Current"); |
---|
95 | p.propstr("ydesc","Current along the Drain"); |
---|
96 | p.propstr("yunits","Amp"); |
---|
97 | p.propstr("yscale","log"); |
---|
98 | |
---|
99 | Rappture::ClientDataXml xmldata; |
---|
100 | xmldata.indent = indent; |
---|
101 | xmldata.tabstop = tabstop; |
---|
102 | xmldata.retStr = NULL; |
---|
103 | p.dump(Rappture::RPCONFIG_XML,&xmldata); |
---|
104 | received = xmldata.retStr; |
---|
105 | |
---|
106 | return test(testname,desc,expected,received); |
---|
107 | } |
---|
108 | |
---|
109 | int main() |
---|
110 | { |
---|
111 | plot_0_0 (); |
---|
112 | plot_1_0 (); |
---|
113 | return 0; |
---|
114 | } |
---|
115 | |
---|
116 | /* |
---|
117 | int main() |
---|
118 | { |
---|
119 | // plot object |
---|
120 | Rappture::Plot *p1 = NULL; |
---|
121 | |
---|
122 | // data arrays |
---|
123 | double x[] = {1,2,3,4,5,6,7,8,9,10}; |
---|
124 | double y[] = {1,4,9,16,25,36,49,64,81,100}; |
---|
125 | double z[] = {1,8,27,64,125,216,343,512,729,1000}; |
---|
126 | |
---|
127 | // number of points in x, y, z arrays |
---|
128 | size_t nPts = 10; |
---|
129 | |
---|
130 | // line format: green line, dotted line style, circle marker |
---|
131 | const char *fmt = "g:o"; |
---|
132 | |
---|
133 | p1 = new Rappture::Plot(); |
---|
134 | |
---|
135 | // add 3 curves to the plot, with format and curve name |
---|
136 | // x vs y, x vs z, x vs x |
---|
137 | // curve name can be used to retrieve curve pointer later |
---|
138 | // blank format means autogenerate the format |
---|
139 | p1->add(nPts,x,y,fmt,"curve1"); |
---|
140 | p1->add(nPts,x,z,"b-*","curve2"); |
---|
141 | p1->add(nPts,x,x,"","curve3"); |
---|
142 | |
---|
143 | p1->propstr("xlabel","Voltage"); |
---|
144 | p1->propstr("xdesc","Voltage along the Gate"); |
---|
145 | p1->propstr("xunits","Volt"); |
---|
146 | p1->propstr("xscale","linear"); |
---|
147 | p1->propstr("ylabel","Current"); |
---|
148 | p1->propstr("ydesc","Current along the Drain"); |
---|
149 | p1->propstr("yunits","Amp"); |
---|
150 | p1->propstr("yscale","log"); |
---|
151 | |
---|
152 | // number of curves in this plot |
---|
153 | size_t curveCnt = p1->count(); |
---|
154 | std::printf("curveCnt = %zu\n",curveCnt); |
---|
155 | |
---|
156 | Rappture::ClientDataXml d; |
---|
157 | d.indent = 0; |
---|
158 | d.tabstop = 4; |
---|
159 | p1->dump(Rappture::RPCONFIG_XML,&d); |
---|
160 | std::printf("xml: %s\n",d.retStr); |
---|
161 | |
---|
162 | delete p1; |
---|
163 | |
---|
164 | return 0; |
---|
165 | } |
---|
166 | */ |
---|