tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / test / dos / setenv.c
blob2f3becf82ea2475d52f121fc1c12bbf3b0d3caec
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
7 #include <stdio.h>
8 #include <proto/dos.h>
10 static LONG testvalue(CONST_STRPTR var, STRPTR expval, ULONG explen,
11 BOOL expnull, LONG cnt)
13 TEXT buffer[10];
14 LONG len, failed = 0;
15 struct LocalVar *lv;
17 if ((len = GetVar(var, buffer, sizeof(buffer), 0)) < 0)
19 printf("test %d ERROR getvar %d\n", (int)cnt, (int)len);
20 failed++;
22 else
23 printf("test %d getvar '%s'\n", (int)cnt, buffer);
25 if ((lv = FindVar(var, 0)) == NULL)
27 printf("test %d ERROR findvar\n", (int)cnt);
28 failed++;
30 else
31 printf("test %d findvar lv_Value=%p, lv_Len=%d\n", (int)cnt,
32 lv->lv_Value, (int)lv->lv_Len);
34 if (lv->lv_Len != explen)
36 printf("test %d ERROR lv_Len, expected %d, found %d\n", (int)cnt,
37 (int)explen, (int)lv->lv_Len);
38 failed++;
41 if (expnull && lv->lv_Value != NULL)
43 printf("test %d ERROR lv_Value expected NULL, found %p\n", (int)cnt,
44 lv->lv_Value);
45 failed++;
48 if (!expnull && lv->lv_Value == NULL)
50 printf("test %d ERROR lv_Value expected not NULL, found %p\n",
51 (int)cnt, lv->lv_Value);
52 failed++;
55 return failed;
58 int main(void)
60 CONST_STRPTR var = "abc";
61 STRPTR val = "cde";
62 LONG cnt = 1, failed = 0;
64 /* Behavior validated with OS3.x */
66 printf("test %d setvar '%s'\n", (int)cnt, val);
67 if (SetVar(var, val, strlen(val), 0) == DOSFALSE)
69 printf("error setvar\n");
70 failed++;
72 failed += testvalue(var, val, 3, FALSE, cnt++);
74 val = "";
75 printf("test %d setvar '%s'\n", (int)cnt, val);
76 if (SetVar(var, val, strlen(val), 0) == DOSFALSE)
78 printf("error setvar\n");
79 failed++;
81 failed += testvalue(var, val, 0, TRUE, cnt++);
83 val = "abcd";
84 printf("test %d setvar '%s'\n", (int)cnt, val);
85 if (SetVar(var, val, strlen(val), 0) == DOSFALSE)
87 printf("error setvar\n");
88 failed++;
90 failed += testvalue(var, val, 4, FALSE, cnt++);
92 val = "";
93 printf("test %d setvar '%s'\n", (int)cnt, val);
94 if (SetVar(var, val, strlen(val), 0) == DOSFALSE)
96 printf("error setvar\n");
97 failed++;
99 failed += testvalue(var, val, 0, TRUE, cnt++);
101 val = "";
102 printf("test %d setvar '%s'\n", (int)cnt, val);
103 if (SetVar(var, val, strlen(val), 0) == DOSFALSE)
105 printf("error setvar\n");
106 failed++;
108 failed += testvalue(var, val, 0, TRUE, cnt++);
110 return failed == 0 ? RETURN_OK : RETURN_ERROR;