[prev in list] [next in list] [prev in thread] [next in thread] 

List:       oprofile-commits
Subject:    [oprof-cvs] CVS: oprofile/libutil/tests Makefile.am,NONE,1.1 file_tests.c,NONE,1.1 string_tests.c,NO
From:       John Levon <movement () users ! sourceforge ! net>
Date:       2003-09-26 13:23:34
[Download RAW message or body]

Update of /cvsroot/oprofile/oprofile/libutil/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv10731/libutil/tests

Added Files:
	Makefile.am file_tests.c string_tests.c 
Log Message:
libutil tests - note the rel_to_abs_path failure, phe what's the issue ?


--- NEW FILE: Makefile.am ---
AM_CPPFLAGS = \
	-I ${top_srcdir}/libutil

AM_CFLAGS = @OP_CFLAGS@

noinst_PROGRAMS = file_tests string_tests

file_tests_SOURCES = file_tests.c
file_tests_LDADD = ../libutil.a
string_tests_SOURCES = string_tests.c
string_tests_LDADD = ../libutil.a

TESTS = file_tests string_tests

--- NEW FILE: file_tests.c ---
/**
 * @file file_tests.c
 *
 * @remark Copyright 2002 OProfile authors
 * @remark Read the file COPYING
 *
 * @author John Levon
 * @author Philippe Elie
 */

#include "op_file.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

static char * tests[][2] = {
	{ "/foo/bar/../quux", "/foo/quux" },
	{ "/../foo/bar/", "/foo/bar" },
	{ "/../../foo/bar/", "/foo/bar" },
	{ "/../../foo/bar/.", "/foo/bar" },
	{ "/../../foo/bar/./", "/foo/bar" },
	{ "/foo/./bar", "/foo/bar" },
	{ "/foo/././bar", "/foo/bar" },
	{ "/foo///", "/foo" },
	{ "../", "/" },
	{ "./", "/fakebase" },
	{ "./../", "/" },
	{ "foo/../bar/../" , "/fakebase" },
	{ "../../../../../" "/" },
	{ NULL, NULL },
};

int main()
{
	size_t i = 0;

	while (tests[i][0]) {
		char * res = op_relative_to_absolute_path(tests[i][0], "/fakebase");
		if (!res) {
			fprintf(stderr, "NULL return for %s\n", tests[i][0]);
			exit(EXIT_FAILURE);
		}

		if (strcmp(res, tests[i][1])) {
			fprintf(stderr, "%s does not match %s given %s\n",
			        res, tests[i][1], tests[i][0]);
			exit(EXIT_FAILURE);
		}
		free(res);
		++i;
	}

	return EXIT_SUCCESS;
}

--- NEW FILE: string_tests.c ---
/**
 * @file string_tests.c
 *
 * @remark Copyright 2002 OProfile authors
 * @remark Read the file COPYING
 *
 * @author John Levon
 * @author Philippe Elie
 */

#include "op_string.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void error(char const * str)
{
	fprintf(stderr, "%s\n", str);
	exit(EXIT_FAILURE);
}


int main()
{
	if (!strisprefix("", ""))
		error("\"\" is not a prefix of \"\"");
	if (!strisprefix("a", ""))
		error("\"\" is not a prefix of a");
	if (!strisprefix("a", "a"))
		error("a is not a prefix of a");
	if (!strisprefix("aa", "a"))
		error("a is not a prefix of aa");
	if (strisprefix("a", "b"))
		error("b is a prefix of a");

	if (strcmp(skip_ws(""), ""))
		error("skip_ws of \"\" is not \"\"");
	if (strcmp(skip_ws("\na"), "a"))
		error("skip_ws of \\na is not a");
	if (strcmp(skip_ws("\n\na"), "a"))
		error("skip_ws of \\n\\na is not a");
	if (strcmp(skip_ws("\n a"), "a"))
		error("skip_ws of \\n a is not a");
	if (strcmp(skip_ws("\n \ta"), "a"))
		error("skip_ws of \\n \\ta is not a");
	if (strcmp(skip_ws("\n \t"), ""))
		error("skip_ws of \\n \\t is not \"\"");
	if (strcmp(skip_ws(" "), ""))
		error("skip_ws of \" \" is not \"\"");

	if (strcmp(skip_nonws(""), ""))
		error("skip_nonws of \"\" is not \"\"");
	if (strcmp(skip_nonws("a"), ""))
		error("skip_nonws of a is not \"\"");
	if (strcmp(skip_nonws("\n"), "\n"))
		error("skip_nonws of \\n is not \\n");
	if (strcmp(skip_nonws(" "), " "))
		error("skip_nonws of \" \" is not \" \"");
	if (strcmp(skip_nonws("\t"), "\t"))
		error("skip_nonws of \\t is not \\t");
	if (strcmp(skip_nonws("a\n"), "\n"))
		error("skip_nonws of a\\n is not \\n");
	if (strcmp(skip_nonws("ab"), ""))
		error("skip_nonws of ab is not \"\"");

	if (!empty_line(""))
		error("empty_line is false for \"\"");
	if (!empty_line("\n\t "))
		error("empty_line is false for \"\\n\\n \"");
	if (!empty_line(" "))
		error("empty_line is false for \" \"");
	if (empty_line("\r"))
		error("empty_line is true for \\r");

	if (comment_line(""))
		error("comment_line is true for \"\"");
	if (comment_line("\n"))
		error("comment_line is true for \n");
	if (!comment_line("#"))
		error("comment_line is false for #");
	if (!comment_line(" #"))
		error("comment_line is false for \" #\"");
	/* this is what the spec says */
	if (!comment_line("\n#"))
		error("comment_line is false for \\n#");
	if (!comment_line("\t#"))
		error("comment_line is false for \\t#");

	return EXIT_SUCCESS;
}



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Oprofile-commits mailing list
Oprofile-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oprofile-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic