1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-24 15:31:17 +00:00
C02/test/memtest.c02
2020-09-30 12:34:41 -04:00

116 lines
2.6 KiB
Plaintext

/*******************************************
* TESTMEM - Test Array Handling Functions *
*******************************************/
//Specify System Header using -H option
#include <stddef.h02>
#include <stdlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <intlib.h02>
#include <memory.h02>
char c, d, f, i, n, p;
char rlen, rcmp, rpos;
char byts[255];
char lttr[255];
char nmbr[255];
char temp[255];
char dest[255];
const char less = "less";
const char more = "more";
const char most = "most";
const char fail = " Fail ";
const char pass = " Pass ";
void prtemp() {
puts("temp: ");
for (i=0; i<255; i++) {
prbyte(temp[i]);
//putchr(' ');
}
}
main:
//Populate arrays
i = 0; c = 'a'; d = '0';
do {
byts[i] = i;
lttr[i] = c;
c++; if (c>'z') c = 'a';
nmbr[i] = d;
d++; if (d>'9') d = '0';
i++;
} while (i>0);
//Test memchr()
putln("memdst(&byts);"); memdst(&byts);
puts("memchr(i, 255);");
p = #TRUE;
for (i=0; i<255; i++) {
//prbyte(i); prchr('='); prbyte(byts[i]); prchr(',');
c = memchr(i,255);
//prbyte(c); prchr(' '); prchr(' ');
if (c <> i) p = #FALSE;
}
if (p) putln(&pass); else putln(&fail);
newlin();
//Test memcmp()
setdst(&less); printf("less=\"%s\", ");
setdst(&more); printf("more=\"%s\", ");
setdst(&most); printf("most=\"%s\"\n");
putln("memdst(&more);");
memdst(&more);
rcmp = memcmp(2, &most);
printf(rcmp,"memcmp(2, &most)=$%x:");
if (!rcmp) puts(&pass); else puts(&fail);
rcmp = memcmp(4, &most);
printf(rcmp,"memcmp(4, &most)=$%x:");
if (rcmp :-) putln(&pass); else putln(&fail);
rcmp = memcmp(4, &more);
printf("memcmp(4, &more)=$%x:");
if (!rcmp) puts(&pass); else puts(&fail);
rcmp = memcmp(4, &less);
printf("memcmp(4, &less)=$%x:");
if (rcmp > 0) putln(&pass); else putln(&fail);
newlin();
//Test memset() and memcpy()
putln("memdst(&temp);"); memdst(&temp);
puts("memset(0,20); "); memset(0,20);
puts("temp="); putln(&temp);
puts("memset('@',20); "); memset('@',20);
puts("temp="); putln(&temp);
puts("memcpy(10, &lttr); "); memcpy(10, &lttr);
puts("temp="); putln(&temp);
puts("memcmp(10, &lttr);");
rcmp = memcmp(10, &lttr);
if (!rcmp) putln(&pass); else putln(&fail);
puts("memcmp(11, &lttr);");
rcmp = memcmp(11, &lttr);
if (rcmp > 0) putln(&pass); else putln(&fail);
newlin();
memdst(&temp); memcpy(7,"ABCDEF"); printf("temp=\"%s\", ");
memdst(&dest); memcpy(7,"123456"); printf("dest=\"%s\"\n");
putln("memdst(&dest);memswp(3,&temp);");
memdst(&dest); memswp(3,&temp);
memdst(&temp); printf("temp=\"%s\":"); florps(memcmp(7,"123DEF"));
memdst(&dest); printf("dest=\"%s\":"); florps(memcmp(7,"ABC456"));
newlin();
goto exit;
void florps(rcmp) {if (rcmp) putln(&fail); else putln(&pass);}