clamav/unit_tests/check_disasm.c

79 lines
2.2 KiB
C
Raw Normal View History

2008-07-28 19:22:15 +00:00
/*
* Unit tests for JS normalizer.
*
* Copyright (C) 2008 Sourcefire, Inc.
*
* Authors: Török Edvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdio.h>
#ifdef HAVE_CHECK
#include <check.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
2008-07-29 02:11:17 +00:00
#include <string.h>
2008-07-28 19:22:15 +00:00
#include "../libclamav/clamav.h"
#include "../libclamav/others.h"
#include "../libclamav/disasm.h"
2008-07-29 02:11:17 +00:00
#include "checks.h"
2008-07-28 19:22:15 +00:00
START_TEST (test_disasm_basic) {
char file[]="disasmXXXXXX";
2008-07-29 02:11:17 +00:00
char ref[]="\xc2\x00\x00\x00\x00\
\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
2008-07-28 19:22:15 +00:00
int fd = mkstemp(file);
uint8_t buf[] = {0x33, 0xc0};
off_t *d;
off_t size;
disasmbuf(buf, 2, fd);
size = lseek(fd, 0, SEEK_CUR);
2008-07-29 02:11:17 +00:00
fail_unless(size==sizeof(ref)-1, "disasm size mismatch(value %u, expected: %u)", size, sizeof(ref)-1);
2008-07-28 19:22:15 +00:00
lseek(fd, 0, SEEK_SET);
d=malloc(size);
2008-07-29 02:11:17 +00:00
fail_unless(d!=NULL, "disasm malloc(%u) failed", size);
fail_unless(read(fd, d, size)==size, "disasm read failed");
2008-07-28 19:22:15 +00:00
close(fd);
2008-07-29 02:11:17 +00:00
fail_unless(!memcmp(d, ref, size), "disasm read failed");
2008-07-28 19:22:15 +00:00
free(d);
unlink(file);
}
END_TEST
Suite *test_disasm_suite(void)
{
Suite *s = suite_create("disasm");
TCase *tc_disasm;
tc_disasm = tcase_create("disasm");
suite_add_tcase (s, tc_disasm);
tcase_add_test(tc_disasm, test_disasm_basic);
return s;
}
#endif