revert between 56095 -> 55830 in arch
[AROS.git] / arch / m68k-all / test / bcpl_strings.c
blob857f2e6bac69c7b6f7e219a27f56b5e4c82d4ae4
1 /*
2 * Copyright (C) 2012, The AROS Development Team
3 * All right reserved.
4 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
6 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
8 * BCPL string function tests
9 */
11 #include <string.h> /* memset */
13 #define BCPL(x,func) const int BCPL_##func = (x) / 4;
14 #include "bcpl.inc"
15 #undef BCPL
17 #include <aros/asmcall.h>
18 #include <proto/exec.h>
19 #include <proto/dos.h>
21 static ULONG BCPL_Thunk(struct Library *DOSBase, int gvfunc, ULONG d1, ULONG d2, ULONG d3, ULONG d4)
23 struct Process *me = (struct Process *)FindTask(NULL);
24 ULONG *gv = (ULONG *)me->pr_GlobVec;
26 return AROS_UFC12(ULONG, (APTR)((struct DosLibrary *)DOSBase)->dl_A5,
27 AROS_UFCA(ULONG, 0, D0),
28 AROS_UFCA(ULONG, d1, D1),
29 AROS_UFCA(ULONG, d2, D2),
30 AROS_UFCA(ULONG, d3, D3),
31 AROS_UFCA(ULONG, d4, D4),
32 AROS_UFCA(APTR, 0, A0),
33 AROS_UFCA(APTR, me->pr_Task.tc_SPLower, A1),
34 AROS_UFCA(APTR, gv, A2),
35 AROS_UFCA(APTR, 0, A3),
36 AROS_UFCA(APTR, gv[gvfunc], A4),
37 AROS_UFCA(APTR, ((struct DosLibrary *)DOSBase)->dl_A5, A5),
38 AROS_UFCA(APTR, ((struct DosLibrary *)DOSBase)->dl_A6, A6));
41 #define BCPL_THUNK1(func, a1) BCPL_Thunk(DOSBase, BCPL_##func, a1, 0, 0, 0)
42 #define BCPL_THUNK2(func, a1, a2) BCPL_Thunk(DOSBase, BCPL_##func, a1, a2, 0, 0)
43 #define BCPL_THUNK3(func, a1, a2, a3) BCPL_Thunk(DOSBase, BCPL_##func, a1, a2, a3, 0)
44 #define BCPL_THUNK4(func, a1, a2, a3, a4) BCPL_Thunk(DOSBase, BCPL_##func, a1, a2, a3, a4)
46 #define VERIFY(f) do { total++; int _val = ({f}); if (_val) { Printf("x");} else { Printf("."); passed++; } } while (0)
48 __startup int _main(void)
50 struct Library *DOSBase;
51 TEXT buff[512];
52 STRPTR cp = &buff[128], val;
53 BSTR bval;
54 int total = 0, passed = 0;
56 if ((DOSBase = OpenLibrary("dos.library", 0))) {
57 Printf("Testing BCPL string functions:\n");
59 /* toCStr Testing */
60 Printf("toCStr: ");
62 VERIFY(
63 memset(buff, 0x99, sizeof(buff));
64 cp[0] = 0;
65 val = (STRPTR)BCPL_THUNK1(toCStr, MKBADDR(cp));
67 (val == cp) && (val[0] == 0) &&
68 (val[-1] == 0x99) && (val[1] == 0x99);
71 VERIFY(
72 memset(buff, 0x99, sizeof(buff));
73 cp[0] = 1;
74 cp[1] = 'a';
75 val = (STRPTR)BCPL_THUNK1(toCStr, MKBADDR(cp));
77 (val == cp) && (val[0] == 'a') &&
78 (val[1] == 0) && (val[2] == 0x99) &&
79 (val[-1] == 0x99);
82 VERIFY(
83 memset(buff, 0x99, sizeof(buff));
84 memset(cp, 'b', 256);
85 cp[0] = 255;
86 val = (STRPTR)BCPL_THUNK1(toCStr, MKBADDR(cp));
88 (val == cp) && (val[0] == 1) &&
89 (val[1] == 'b') && (val[255] == 0x0) &&
90 (val[256] == 0x99) && (val[-1] == 0x99);
93 Printf("%ld/%ld\n", passed, total);
95 /* toBSTR Testing */
96 passed = failed = 0;
97 Printf("toBSTR: ");
99 VERIFY(
100 memset(buff, 0x99, sizeof(buff));
101 cp[0] = 0;
102 bval = (BSTR)BCPL_THUNK2(toBSTR, (IPTR)NULL, MKBADDR(cp));
104 (bval == MKBADDR(cp)) && (cp[0] == 0) &&
105 (cp[-1] == 0x99) && (cp[1] == 0x99);
108 VERIFY(
109 memset(buff, 0x99, sizeof(buff));
110 bval = (BSTR)BCPL_THUNK2(toBSTR, (IPTR)"", MKBADDR(cp));
112 (bval == MKBADDR(cp)) && (cp[0] == 0) &&
113 (cp[-1] == 0x99) && (cp[1] == 0x99);
116 VERIFY(
117 memset(buff, 0x99, sizeof(buff));
118 bval = (BSTR)BCPL_THUNK2(toBSTR, (IPTR)"a", MKBADDR(cp));
120 (bval == MKBADDR(cp)) && (cp[0] == 1) &&
121 (cp[1] == 'a') &&
122 (cp[-1] == 0x99) && (cp[2] == 0x99);
125 VERIFY(
126 memset(buff, 0x99, sizeof(buff));
127 bval = (BSTR)BCPL_THUNK2(toBSTR, (IPTR)"123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678912345", MKBADDR(cp));
129 (bval == MKBADDR(cp)) && (cp[0] == 255) &&
130 (cp[1] == '1') && (cp[255] == '5') &&
131 (cp[-1] == 0x99) && (cp[256] == 0x99);
134 VERIFY(
135 memset(buff, 0x99, sizeof(buff));
136 bval = (BSTR)BCPL_THUNK2(toBSTR, (IPTR)"1234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789123456", MKBADDR(cp));
138 (bval == MKBADDR(cp)) && (cp[0] == 0) &&
139 (cp[-1] == 0x99) && (cp[256] == 0x99);
142 Printf("%ld/%ld\n", passed, total);
144 CloseLibrary(DOSBase);
147 return (passed == total) ? RETURN_OK : RETURN_FAIL;