mirror of
https://github.com/ksherlock/mpw.git
synced 2024-11-21 09:30:55 +00:00
add something like unit tests.
This commit is contained in:
parent
cf4a8e2fcc
commit
d2bca7efe0
40
test/makefile
Normal file
40
test/makefile
Normal file
@ -0,0 +1,40 @@
|
||||
LIBS = \
|
||||
{Libraries}Stubs.o \
|
||||
{CLibraries}StdCLib.o \
|
||||
{Libraries}Interface.o \
|
||||
{Libraries}Runtime.o \
|
||||
{Libraries}ToolLibs.o
|
||||
|
||||
PPC_LIBS = {SharedLibraries}InterfaceLib \
|
||||
{SharedLibraries}StdCLib \
|
||||
{PPCLibraries}StdCRuntime.o \
|
||||
{PPCLibraries}PPCCRuntime.o
|
||||
|
||||
LDFLAGS = -w -c 'MPS ' -t MPST \
|
||||
-sn STDIO=Main -sn INTENV=Main -sn %A5Init=Main
|
||||
|
||||
SCFLAGS = -p
|
||||
|
||||
TARGETS = test_new_handle test_new_handle_2 test_new_pointer
|
||||
|
||||
all : $(TARGETS)
|
||||
|
||||
clean :
|
||||
rm -f $(TARGETS) o/*
|
||||
|
||||
test_new_handle : o/test_new_handle.o
|
||||
mpw Link $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
test_new_handle_2 : o/test_new_handle_2.o
|
||||
mpw Link $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
test_new_pointer : o/test_new_pointer.o
|
||||
mpw Link $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
|
||||
# % : o/%.o
|
||||
# mpw Link $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
o/%.o : %.c
|
||||
mpw SC $(SCFLAGS) $< -o $@
|
||||
|
30
test/test_new_handle.c
Normal file
30
test/test_new_handle.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <MacMemory.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void test_new_handle(unsigned size)
|
||||
{
|
||||
unsigned long total = 0;
|
||||
unsigned long count = 0;
|
||||
|
||||
for(;;) {
|
||||
|
||||
Handle h = NewHandle(size);
|
||||
if (!h) {
|
||||
fprintf(stdout, "memory error: %d\n", MemError());
|
||||
break;
|
||||
}
|
||||
|
||||
total += size;
|
||||
count++;
|
||||
}
|
||||
|
||||
fprintf(stdout, "%ld handles allocated\n", count);
|
||||
fprintf(stdout, "%ld bytes allocated\n", total);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_new_handle(1024 * 1024);
|
||||
return 0;
|
||||
}
|
110
test/test_new_handle_2.c
Normal file
110
test/test_new_handle_2.c
Normal file
@ -0,0 +1,110 @@
|
||||
#include <MacMemory.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum {
|
||||
TimeLM = 0x020C
|
||||
};
|
||||
|
||||
/* arc4random */
|
||||
|
||||
struct {
|
||||
unsigned char i;
|
||||
unsigned char j;
|
||||
unsigned char s[256];
|
||||
} rs;
|
||||
|
||||
void arc4_init(void)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
rs.s[n] = n;
|
||||
|
||||
rs.i = 0;
|
||||
rs.j = 0;
|
||||
}
|
||||
|
||||
void arc4_addrandom(const unsigned char *dat, int datlen)
|
||||
{
|
||||
int n;
|
||||
unsigned char si;
|
||||
|
||||
rs.i--;
|
||||
for (n = 0; n < 256; n++) {
|
||||
rs.i = (rs.i + 1);
|
||||
si = rs.s[rs.i];
|
||||
rs.j = (rs.j + si + dat[n % datlen]);
|
||||
rs.s[rs.i] = rs.s[rs.j];
|
||||
rs.s[rs.j] = si;
|
||||
}
|
||||
rs.j = rs.i;
|
||||
}
|
||||
|
||||
|
||||
unsigned char arc4_getbyte(void)
|
||||
{
|
||||
unsigned char si, sj;
|
||||
|
||||
rs.i = (rs.i + 1);
|
||||
si = rs.s[rs.i];
|
||||
rs.j = (rs.j + si);
|
||||
sj = rs.s[rs.j];
|
||||
rs.s[rs.i] = sj;
|
||||
rs.s[rs.j] = si;
|
||||
return (rs.s[(si + sj) & 0xff]);
|
||||
}
|
||||
|
||||
unsigned long arc4_get24(void)
|
||||
{
|
||||
unsigned long val;
|
||||
|
||||
val |= arc4_getbyte() << 16;
|
||||
val |= arc4_getbyte() << 8;
|
||||
val |= arc4_getbyte();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void test(void)
|
||||
{
|
||||
|
||||
unsigned i,j;
|
||||
unsigned errors = 0;
|
||||
unsigned success = 0;
|
||||
|
||||
for (i = 0; i < 10000; ++i)
|
||||
{
|
||||
Handle h[5];
|
||||
for (j = 0; j < 5; ++j) {
|
||||
unsigned long size = arc4_get24() >> 3;
|
||||
Handle hh = NewHandle(size);
|
||||
|
||||
if (hh) {
|
||||
success++;
|
||||
} else {
|
||||
fprintf(stdout, "NewHandle failed (%u): %d\n", size, MemError());
|
||||
errors++;
|
||||
}
|
||||
|
||||
h[j] = hh;
|
||||
}
|
||||
|
||||
for (j = 0; j < 5; ++j) {
|
||||
DisposeHandle(h[j]);
|
||||
}
|
||||
|
||||
}
|
||||
fprintf(stdout, "NewHandle failed: %u\n", errors);
|
||||
fprintf(stdout, "NewHandle succeeded: %u\n", success);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
// init with the time.
|
||||
arc4_init();
|
||||
arc4_addrandom((const unsigned char *)TimeLM, 4);
|
||||
|
||||
test();
|
||||
return 0;
|
||||
}
|
31
test/test_new_pointer.c
Normal file
31
test/test_new_pointer.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <MacMemory.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void test_new_pointer(unsigned size)
|
||||
{
|
||||
unsigned long total = 0;
|
||||
unsigned long count = 0;
|
||||
|
||||
for(;;) {
|
||||
|
||||
void *p = NewPtr(size);
|
||||
if (!p) {
|
||||
fprintf(stdout, "memory error: %d\n", MemError());
|
||||
break;
|
||||
}
|
||||
|
||||
total += size;
|
||||
count++;
|
||||
}
|
||||
|
||||
fprintf(stdout, "%ld pointers allocated\n", count);
|
||||
fprintf(stdout, "%ld bytes allocated\n", total);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_new_pointer(1024 * 1024);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user