mrfioc2  2.3.0
linkoptionsTest.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2010 Brookhaven Science Associates, as Operator of
3 * Brookhaven National Laboratory.
4 * mrfioc2 is distributed subject to a Software License Agreement found
5 * in file LICENSE that is included with this distribution.
6 \*************************************************************************/
7 /*
8  * Author: Michael Davidsaver <mdavidsaver@gmail.com>
9  */
10 
11 #include <stdio.h>
12 #include <string.h>
13 
14 #include "linkoptions.h"
15 
16 #include "epicsUnitTest.h"
17 #include "epicsString.h"
18 #include "testMain.h"
19 
20 struct adev {
21  epicsUInt32 a;
22  double b;
23  char c[10];
24  int d;
25 };
26 
27 static const
28 linkOptionEnumType colorEnum[] = { {"Red",1}, {"Green",2}, {"Blue",3}, {NULL,0} };
29 
30 static const
31 linkOptionDef myStructDef[] = {
32  linkInt32 (struct adev, a, "A" , 0, 0),
33  linkDouble(struct adev, b, "BEE" , 1, 0),
34  linkString(struct adev, c, "name" , 1, 0),
35  linkEnum (struct adev, d, "Color" , 1, 0, colorEnum),
37 };
38 
39 const char one[]="BEE=4.2, A=42, Color=Green, name=fred";
40 const char two[]="BEE=2.4, Color=Blue, name=ralph";
41 
42 MAIN(linkoptionsTest)
43 {
44  (void)argc;
45  (void)argv;
46 
47  struct adev X;
48 
49  testPlan(10);
50 
51  X.a=0;
52  X.b=0.0;
53  X.c[0]='\0';
54  X.d=0;
55 
56  testOk1(linkOptionsStore(myStructDef, &X, one, 0)==0);
57 
58  testOk1(X.a==42);
59  testOk1(X.b==4.2);
60  testOk1(strcmp(X.c, "fred")==0);
61  testOk1(X.d==2);
62 
63  X.a=14;
64  X.b=0.0;
65  X.c[0]='\0';
66  X.d=0;
67 
68  testOk1(linkOptionsStore(myStructDef, &X, two, 0)==0);
69 
70  testOk1(X.a==14);
71  testOk1(X.b==2.4);
72  testOk1(strcmp(X.c, "ralph")==0);
73  testOk1(X.d==3);
74 
75  return 0;
76 }
#define linkDouble(Struct, Member, Name, Req, Over)
Definition: linkoptions.h:102
MAIN(linkoptionsTest)
#define linkOptionEnd
Definition: linkoptions.h:111
int epicsShareAPI linkOptionsStore(const linkOptionDef *opts, void *user, const char *str, int options)
Parse a string a store the result.
Definition: linkoptions.c:135
#define linkInt32(Struct, Member, Name, Req, Over)
Definition: linkoptions.h:99
const char two[]
#define linkEnum(Struct, Member, Name, Req, Over, Enums)
Definition: linkoptions.h:108
const char one[]
Hardware link parsing and storage.
#define linkString(Struct, Member, Name, Req, Over)
Definition: linkoptions.h:105
double b
epicsUInt32 a
char c[10]