view DPP/test/memory_test.c @ 3:4e98faa1d831

add automaton
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Thu, 19 Apr 2012 13:41:11 +0900
parents a89b61162c29
children
line wrap: on
line source

#include <stdio.h>
#include <strings.h>

#include "memory.h"

static int array1[100];
static int array2[100];
static int array3[200];
static int array4[200];

MemoryPtr db;

int main()
{
    int found;
    /* basic unit test */

    MemoryPtr m1 = create_memory(array1,sizeof(array1));
    MemoryPtr m2 = create_memory(array2,sizeof(array2));

    compute_memory_hash1(m1);
    compute_memory_hash1(m2);

    printf("cmp %d ... 0 \n", cmp_content(m1,m2));

    array1[0x55] = 0x55;
    compute_memory_hash1(m1);

    printf("cmp %d .... 1 or -1 \n", cmp_content(m1,m2));

    /* memory fragments */

    MemoryPtr a1 = add_memory(array1,sizeof(array1),&db);
    MemoryPtr a2 = add_memory(array2,sizeof(array2),&db);
    MemoryPtr a3 = add_memory(array3,sizeof(array3),&db);
    MemoryPtr a4 = add_memory(array4,sizeof(array4),&db);

    array1[0x45] = 0xff;
    array2[0x46] = 0xf0;
    array3[0x47] = 0xe8;
    array4[0x48] = 0xe8;

    a1 = add_memory(array1,sizeof(array1),&db);
    a2 = add_memory(array2,sizeof(array2),&db);
    a3 = add_memory(array3,sizeof(array3),&db);
    a4 = add_memory(array4,sizeof(array4),&db);

    array2[0x55] = 0x55;
    array1[0x46] = 0xf0;
    array2[0x45] = 0xff;
    array3[0x48] = 0xe8;
    array4[0x47] = 0xe8;

    a1 = add_memory(array1,sizeof(array1),&db);
    a2 = add_memory(array2,sizeof(array2),&db);
    a3 = add_memory(array3,sizeof(array3),&db);
    a4 = add_memory(array4,sizeof(array4),&db);

    bzero(array1,sizeof(array1));

    printf("zero\n");
    a1 = add_memory(array1,sizeof(array1),&db);
    found = memory_lookup(a1,&db,0,&a2);
    if (found) {
	printf("found\n");
	if (cmp_memory(a1,a2)) printf("different\n"); else printf("same\n");
    } else {
	printf("not found\n");
    }

    printf("modified\n");
    array1[0x10] = 0xf0;
    found = memory_lookup(m1,&db,0,&a2);
    if (found) {
	printf("found\n");
	if (cmp_memory(a1,a2)) printf("same\n"); else printf("different\n");
    } else {
	printf("not found\n");
    }

    return 0;
}

/* end */