MIDAS
Loading...
Searching...
No Matches
get_record_test.cxx
Go to the documentation of this file.
1//
2// get_record_test: test db_create_record(), db_get_record(), db_set_record(), etc
3//
4// Author: Konstantin Olchanski, 2017-OCT-11
5//
6
7#undef NDEBUG // midas required assert() to be always enabled
8
9#include <assert.h>
10
11#include "midas.h"
12#include "msystem.h"
13#include "history.h"
14#include "mstrlcpy.h"
15
16typedef struct {
18 INT iarray[2];
19 char svalue[20];
20 char sarray[2][32];
22
24{
25 printf("test1_struct: ivalue %d, iarray %d %d, svalue [%s], sarray [%s] [%s]\n", s->ivalue, s->iarray[0], s->iarray[1], s->svalue, s->sarray[0], s->sarray[1]);
26}
27
28#define test1_STR "\
29ivalue = INT : 1\n\
30iarray = INT[2] : \n\
31[0] 1\n\
32[1] 2\n\
33svalue = STRING : [20] /Runinfo/Run number\n\
34sarray = STRING[2] : \n\
35[32] str1\n\
36[32] str2\n\
37"
38
40{
41 int status;
42 printf("test1!\n");
43
44 HNDLE hh;
45 db_find_key(hDB, hKey, "test1", &hh);
46 if (hh) {
47 printf("already exists, skipping!\n");
48 return;
49 }
50 printf("create test1\n");
52 printf("db_create_record status %d\n", status);
53}
54
56{
57 int status;
58 printf("test1a!\n");
59
60 printf("check test1\n");
62 printf("db_check_record status %d\n", status);
63}
64
66{
67 int status;
68 printf("test1b!\n");
69
71
72 HNDLE hh;
73 db_find_key(hDB, hKey, "test1", &hh);
74
75 printf("get test1\n");
76 int size = sizeof(s);
77 status = db_get_record(hDB, hh, &s, &size, 0);
78 printf("db_get_record status %d, size %d/%d\n", status, (int)sizeof(s), size);
79 print_test1(&s);
80}
81
83{
84 int status;
85 printf("test1c - db_get_record1!\n");
86
88
89 HNDLE hh;
90 db_find_key(hDB, hKey, "test1", &hh);
91
92 printf("get test1\n");
93 int size = sizeof(s);
94 status = db_get_record1(hDB, hh, &s, &size, 0, test1_STR);
95 printf("db_get_record1 status %d, size %d/%d\n", status, (int)sizeof(s), size);
96 print_test1(&s);
97}
98
100{
101 int status;
102 printf("test1d - db_get_record2!\n");
103
104 test1_struct s;
105
106 HNDLE hh;
107 db_find_key(hDB, hKey, "test1", &hh);
108
109 printf("get test1\n");
110 int size = sizeof(s);
111 status = db_get_record2(hDB, hh, &s, &size, 0, test1_STR, 0);
112 printf("db_get_record2 status %d, size %d/%d\n", status, (int)sizeof(s), size);
113 print_test1(&s);
114}
115
116typedef struct {
119 double dvalue;
120 char cvalue;
122 float fvalue;
123 double dvalue2;
125 char svalue[10];
126 double dvalue3;
128
130{
131 printf("test2_struct: wvalue %d, dwvalue %d, dvalue %f, cvalue %d, dwvalue2 %d, fvalue %f, dvalue2 %f, cvalue2 %d, svalue [%s], dvalue3 %f\n", s->wvalue, s->dwvalue, s->dvalue, s->cvalue, s->dwvalue2, s->fvalue, s->dvalue2, s->cvalue2, s->svalue, s->dvalue3);
132}
133
134#define test2_STR "\
135wvalue = WORD : 1\n\
136dwvalue = DWORD : 2\n\
137dvalue = DOUBLE : 3.3\n\
138cvalue = CHAR : 4\n\
139dwvalue2 = DWORD : 5\n\
140fvalue = FLOAT : 6.6\n\
141dvalue2 = DOUBLE : 7.7\n\
142cvalue2 = CHAR : 8\n\
143svalue = STRING : [10] 99999\n\
144dvalue3 = DOUBLE : 10.01\n\
145"
146
148{
149 int status;
150 printf("test2!\n");
151
152 HNDLE hh;
153 db_find_key(hDB, hKey, "test2", &hh);
154 if (hh) {
155 printf("already exists, skipping!\n");
156 return;
157 }
158 printf("create test2\n");
160 printf("db_create_record status %d\n", status);
161}
162
164{
165 int status;
166 printf("test2b!\n");
167
168 test2_struct s;
169
170 HNDLE hh;
171 db_find_key(hDB, hKey, "test2", &hh);
172
173 printf("get test2\n");
174 int size = sizeof(s);
175 status = db_get_record(hDB, hh, &s, &size, 0);
176 printf("db_get_record status %d, size %d/%d\n", status, (int)sizeof(s), size);
177 print_test2(&s);
178}
179
181{
182 int status;
183 printf("test2d - db_get_record2!\n");
184
185 test2_struct s;
186
187 HNDLE hh;
188 db_find_key(hDB, hKey, "test2", &hh);
189
190 printf("get test2\n");
191 int size = sizeof(s);
192 status = db_get_record2(hDB, hh, &s, &size, 0, test2_STR, 0);
193 printf("db_get_record2 status %d, size %d/%d\n", status, (int)sizeof(s), size);
194 print_test2(&s);
195}
196
197int main(int argc, char *argv[])
198{
199 int status = 0;
200 HNDLE hDB;
201 char host_name[256];
202 char expt_name[256];
203 host_name[0] = 0;
204 expt_name[0] = 0;
205
207
209 assert(status == CM_SUCCESS);
210
212 assert(status == CM_SUCCESS);
213
214 HNDLE hKey = 0;
215
216 test1(hDB, hKey);
217 //test1a(hDB, hKey);
218 //test1b(hDB, hKey);
219 test1b(hDB, hKey);
220 test1d(hDB, hKey);
221
222 test2(hDB, hKey);
223 test2b(hDB, hKey);
224 test2d(hDB, hKey);
225
227 assert(status == CM_SUCCESS);
228
229 return 0;
230}
231
232/* emacs
233 * Local Variables:
234 * tab-width: 8
235 * c-basic-offset: 3
236 * indent-tabs-mode: nil
237 * End:
238 */
void print_test2(const test2_struct *s)
void test1c(HNDLE hDB, HNDLE hKey)
void print_test1(const test1_struct *s)
void test1(HNDLE hDB, HNDLE hKey)
void test2(HNDLE hDB, HNDLE hKey)
void test2b(HNDLE hDB, HNDLE hKey)
#define test2_STR
void test1d(HNDLE hDB, HNDLE hKey)
void test2d(HNDLE hDB, HNDLE hKey)
void test1b(HNDLE hDB, HNDLE hKey)
#define test1_STR
void test1a(HNDLE hDB, HNDLE hKey)
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
Definition midas.cxx:2297
INT cm_disconnect_experiment(void)
Definition midas.cxx:2846
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
Definition midas.cxx:2134
#define CM_SUCCESS
Definition midas.h:582
unsigned short int WORD
Definition mcstd.h:49
unsigned int DWORD
Definition mcstd.h:51
INT db_get_record1(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align, const char *rec_str)
Definition odb.cxx:11805
INT db_check_record(HNDLE hDB, HNDLE hKey, const char *keyname, const char *rec_str, BOOL correct)
Definition odb.cxx:12972
INT db_get_record(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align)
Definition odb.cxx:11709
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
Definition odb.cxx:12800
INT db_get_record2(HNDLE hDB, HNDLE hKey, void *data, INT *xbuf_size, INT align, const char *rec_str, BOOL correct)
Definition odb.cxx:12169
int main()
Definition hwtest.cxx:23
HNDLE hKey
HNDLE hDB
main ODB handle
Definition mana.cxx:207
char host_name[HOST_NAME_LENGTH]
Definition mana.cxx:242
char expt_name[NAME_LENGTH]
Definition mevb.cxx:44
INT HNDLE
Definition midas.h:132
int INT
Definition midas.h:129
#define TRUE
Definition midas.h:182
#define DEFAULT_ODB_SIZE
Definition midas.h:270
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
char sarray[2][32]