📄 devtest2.c
字号:
/************************************************************************
** MODULE INFORMATION*
**********************
** FILE NAME: devtest2.c
** SYSTEM NAME:
** ORIGINAL AUTHOR(S): Paul Lemmers
** VERSION NUMBER:
** CREATION DATE: 1990/8/14
**
** DESCRIPTION:
** Test file for devlib files (string and memory part).
**
** There are two types of tests:
** Type 1
** Predefined results (Check by testing result, direct
** or with "correct and tested" function).
** Type 2
** Compare result of tested function with result of MSC
** function
**
*************************************************************************
** CHANGES INFORMATION **
*************************
** REVISION: $Revision: 1.2 $
** WORKFILE: $Workfile: devtest2.c $
** LOGINFO: $Log: D:/CPROG/MYDEV/DEVLIB/VCS/DEVTEST2.C_V $
**
** Rev 1.2 17 Dec 1990 14:32:58 PAUL
** os2def.h changes
**
** Rev 1.1 09 Dec 1990 19:06:24 PAUL
** Adaptions for MSC 6.00
**
** Rev 1.0 14 Aug 1990 14:24:58 PAUL
** Initial revision.
*************************************************************************/
#if ! defined(PRD)
static char _pvcs_hdr[] =
"$Header: D:/CPROG/MYDEV/DEVLIB/VCS/DEVTEST2.C_V 1.2 17 Dec 1990 14:32:58 PAUL $";
#endif
#define BUFSIZE 0x100
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <os2def.h>
#include "devlib.h"
int main(int argc, char *argv[]);
void setbufs(int pattern);
int itoa_test(void);
int ltoa_test(void);
int ultoa_test(void);
int sprintf_test(void);
int printf_test(void);
char mscbuf[BUFSIZE];
char mybuf[BUFSIZE];
struct {
int (*pfunc)(void);
char *fname;
} testlist[] = {
{ itoa_test, "itoa" },
{ ltoa_test, "ltoa" },
{ ultoa_test, "ultoa" },
{ sprintf_test, "sprintf" },
{ printf_test, "printf" }
};
int main(int argc, char *argv[])
{
int retc;
int i;
argc; argv;
fprintf(stdout, "Devlib tester.\n");
i = 0;
while ( i < sizeof(testlist)/sizeof(*testlist) )
{
if ( (retc=(*testlist[i].pfunc)()) != 0 )
{
fprintf(stdout, "%s failed", testlist[i].fname);
break; /* stop the other tests */
}
i++;
}
if ( retc )
fprintf(stdout, " FATAL\n");
return(retc);
}
int itoa_test(void)
{
/* Type 1 and 2 test */
static struct _itoatest {
int val;
int base;
char *s;
} ar[] = {
{ 0, 10, "0"},
{ 1, 10, "1"},
{ -1, 10, "-1"},
{ 10, 10, "10"},
{ -10, 10, "-10"},
{ 100, 10, "100"},
{ -100, 10, "-100"},
{ 1000, 10, "1000"},
{ -1000, 10, "-1000"},
{ 10000, 10, "10000"},
{ -10000, 10, "-10000"},
{ 0x7fff, 10, "32767"},
{ 0x8000, 10, "-32768"},
{ 0x9, 0x10, "9" },
{ 0xa, 0x10, "a" },
{ 0x9, 0x10, "9" },
{ 0x10, 0x10, "10" },
{ 0x7fff, 0x10, "7fff" },
{ 0xffff, 0x10, "ffff" },
{ 01, 8, "1" },
{ 07, 8, "7" },
{ 010, 8, "10" }
};
int i;
for ( i=0 ; i<(sizeof(ar)/sizeof(*ar)) ; i++)
{
setbufs(' ');
itoa(ar[i].val, mscbuf, ar[i].base);
dev_itoa(ar[i].val, mybuf, ar[i].base);
if ( strcmp(mscbuf, ar[i].s) )
{
fprintf(stdout, " itoa() failed on test %d\n", i);
return(-1);
}
else if ( memcmp(mscbuf, mybuf, BUFSIZE) )
{
fprintf(stdout, " dev_itoa() failed on test %d\n", i);
return(-1);
}
}
return(0);
}
int ltoa_test(void)
{
/* Type 1 and 2 test */
static struct _ltoatest {
long val;
int base;
char *s;
} ar[] = {
{ 0L, 10, "0"},
{ 1L, 10, "1"},
{ -1L, 10, "-1"},
{ 10L, 10, "10"},
{ -10L, 10, "-10"},
{ 100L, 10, "100"},
{ -100L, 10, "-100"},
{ 1000L, 10, "1000"},
{ -1000L, 10, "-1000"},
{ 10000L, 10, "10000"},
{ -10000L, 10, "-10000"},
{ 100000L, 10, "100000"},
{ -100000L, 10, "-100000"},
{ 0x7fffL, 10, "32767"},
{ 0x8000L, 10, "32768"},
{ 0xffffL, 10, "65535"},
{ 0x10000L, 10, "65536"},
{ 0xffff0000L, 10, "-65536"},
{ 0x7fffffffL, 10, "2147483647"},
{ 0x80000000L, 10, "-2147483648"},
{ 0x9L, 0x10, "9" },
{ 0xaL, 0x10, "a" },
{ 0xfL, 0x10, "f" },
{ 0x10L, 0x10, "10" },
{ 0x7fffL, 0x10, "7fff" },
{ 0xffffL, 0x10, "ffff" },
{ 01L, 8, "1" },
{ 07L, 8, "7" },
{ 010L, 8, "10" }
};
int i;
for ( i=0 ; i<(sizeof(ar)/sizeof(*ar)) ; i++)
{
setbufs(' ');
ltoa(ar[i].val, mscbuf, ar[i].base);
dev_ltoa(ar[i].val, mybuf, ar[i].base);
if ( strcmp(mscbuf, ar[i].s) )
{
fprintf(stdout, " ltoa() failed on test %d\n", i);
return(-1);
}
else if ( memcmp(mscbuf, mybuf, BUFSIZE) )
{
fprintf(stdout, " dev_ltoa() failed on test %d\n", i);
return(-1);
}
}
return(0);
}
int ultoa_test(void)
{
/* Type 1 and 2 test */
static struct _ultoatest {
unsigned long val;
int base;
char *s;
} ar[] = {
{ 0L, 10, "0"},
{ 1L, 10, "1"},
{ 0xffffffff, 10, "4294967295"},
{ 10L, 10, "10"},
{ 100L, 10, "100"},
{ 1000L, 10, "1000"},
{ 10000L, 10, "10000"},
{ 100000L, 10, "100000"},
{ 0x7fffL, 10, "32767"},
{ 0x8000L, 10, "32768"},
{ 0xffffL, 10, "65535"},
{ 0x10000L, 10, "65536"},
{ 0xffff0000L, 10, "4294901760"},
{ 0x9L, 0x10, "9" },
{ 0xaL, 0x10, "a" },
{ 0xfL, 0x10, "f" },
{ 0x10L, 0x10, "10" },
{ 0x7fffL, 0x10, "7fff" },
{ 0xffffL, 0x10, "ffff" },
{ 01L, 8, "1" },
{ 07L, 8, "7" },
{ 010L, 8, "10" }
};
int i;
for ( i=0 ; i<(sizeof(ar)/sizeof(*ar)) ; i++)
{
setbufs(' ');
ultoa(ar[i].val, mscbuf, ar[i].base);
dev_ultoa(ar[i].val, mybuf, ar[i].base);
if ( strcmp(mscbuf, ar[i].s) )
{
fprintf(stdout, " ultoa() failed on test %d\n", i);
return(-1);
}
else if ( memcmp(mscbuf, mybuf, BUFSIZE) )
{
fprintf(stdout, " dev_ultoa() failed on test %d\n", i);
return(-1);
}
}
return(0);
}
int sprintf_test(void)
{
/* Type 1 and 2 test */
static struct _iprt_test {
char *fmt;
int val;
char *s;
} ar1[] = {
{ "d : %d", 1, "d : 1"},
{ "d : %d", 9, "d : 9"},
{ "d : %d", 10, "d : 10"},
{ "d : %d", 100, "d : 100"},
{ "d : %d", 1000, "d : 1000"},
{ "d : %d", 10000, "d : 10000"},
{ "d : %d", -1, "d : -1"},
{ "d : %d", -10000, "d : -10000"},
{ "d : %d", 15, "d : 15"},
/* test width */
{ "d : %1d", 15, "d : 15"},
{ "d : %2d", 15, "d : 15"},
{ "d : %3d", 15, "d : 15"},
{ "d : %4d", 15, "d : 15"},
/* test right allign */
{ "d : %-1d", 15, "d : 15"},
{ "d : %-2d", 15, "d : 15"},
{ "d : %-3d", 15, "d : 15 "},
{ "d : %-4d", 15, "d : 15 "},
/* test zero padding */
{ "d : %01d", 15, "d : 15"},
{ "d : %02d", 15, "d : 15"},
{ "d : %03d", 15, "d : 015"},
{ "d : %04d", 15, "d : 0015"},
/* test width.prec */
{ "d : %1.1d", 1, "d : 1"},
{ "d : %2.1d", 1, "d : 1"},
{ "d : %3.1d", 1, "d : 1"},
{ "d : %1.2d", 1, "d : 01"},
{ "d : %2.2d", 1, "d : 01"},
{ "d : %3.2d", 1, "d : 01"},
{ "d : %1.3d", 1, "d : 001"},
{ "d : %2.3d", 1, "d : 001"},
{ "d : %3.3d", 1, "d : 001"},
/* test .prec */
{ "d : %.1d", 1, "d : 1"},
{ "d : %.2d", 1, "d : 01"},
/* hex */
{ "x : %x", 15, "x : f"},
/* octal */
{ "d : %o", 15, "d : 17"}
};
static struct _iprt_test ar2[] = {
{"s : \"%s\" x: %x", 0xfedc, "s : \"test\" x: fedc"}
};
static struct _iprt_test ar3[] = {
{"s : \"%Fs\" x: %x", 0xfedc, "s : \"test\" x: fedc"}
};
static char test_str[] = {"test"};
int i;
int retc = 0;
for ( i=0 ; i<(sizeof(ar1)/sizeof(*ar1)) ; i++)
{
setbufs(' ');
sprintf(mscbuf, ar1[i].fmt, ar1[i].val);
dev_sprintf(mybuf, ar1[i].fmt, ar1[i].val);
if ( strcmp(mscbuf, ar1[i].s) )
{
fprintf(stdout, " sprintf() failed on test 1.%d\n", i);
retc = -1;
}
else if ( memcmp(mscbuf, mybuf, BUFSIZE) )
{
fprintf(stdout, " dev_sprintf() failed on test 1.%d\n", i);
retc = -1;
}
}
for ( i=0 ; i<(sizeof(ar2)/sizeof(*ar2)) ; i++)
{
setbufs(' ');
sprintf(mscbuf, ar2[i].fmt, test_str, ar2[i].val);
dev_sprintf(mybuf, ar2[i].fmt, test_str, ar2[i].val);
if ( strcmp(mscbuf, ar2[i].s) )
{
fprintf(stdout, " sprintf() failed on test 2.%d\n", i);
retc = -1;
}
else if ( memcmp(mscbuf, mybuf, BUFSIZE) )
{
fprintf(stdout, " dev_sprintf() failed on test 2.%d\n", i);
retc = -1;
}
}
for ( i=0 ; i<(sizeof(ar3)/sizeof(*ar3)) ; i++)
{
setbufs(' ');
sprintf(mscbuf, ar3[i].fmt, (char far *)test_str, ar3[i].val);
dev_sprintf(mybuf, ar3[i].fmt, (char far *)test_str, ar3[i].val);
if ( strcmp(mscbuf, ar3[i].s) )
{
fprintf(stdout, " sprintf() failed on test 3.%d\n", i);
retc = -1;
}
else if ( memcmp(mscbuf, mybuf, BUFSIZE) )
{
fprintf(stdout, " dev_sprintf() failed on test 3.%d\n", i);
retc = -1;
}
}
return(retc);
}
int printf_test(void)
{
dev_printf("%d. This is DosPutMessage without CR,LF", 1);
return(0);
}
void setbufs(int pattern)
{
memset(mscbuf, pattern, BUFSIZE);
memset(mybuf, pattern, BUFSIZE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -