Home | History | Annotate | Download | only in tests
      1 /**
      2  * @file string_tests.c
      3  *
      4  * @remark Copyright 2002 OProfile authors
      5  * @remark Read the file COPYING
      6  *
      7  * @author John Levon
      8  * @author Philippe Elie
      9  */
     10 
     11 #include "op_string.h"
     12 
     13 #include <stdlib.h>
     14 #include <stdio.h>
     15 #include <string.h>
     16 
     17 void error(char const * str)
     18 {
     19 	fprintf(stderr, "%s\n", str);
     20 	exit(EXIT_FAILURE);
     21 }
     22 
     23 
     24 int main()
     25 {
     26 	if (!strisprefix("", ""))
     27 		error("\"\" is not a prefix of \"\"");
     28 	if (!strisprefix("a", ""))
     29 		error("\"\" is not a prefix of a");
     30 	if (!strisprefix("a", "a"))
     31 		error("a is not a prefix of a");
     32 	if (!strisprefix("aa", "a"))
     33 		error("a is not a prefix of aa");
     34 	if (strisprefix("a", "b"))
     35 		error("b is a prefix of a");
     36 
     37 	if (strcmp(skip_ws(""), ""))
     38 		error("skip_ws of \"\" is not \"\"");
     39 	if (strcmp(skip_ws("\na"), "a"))
     40 		error("skip_ws of \\na is not a");
     41 	if (strcmp(skip_ws("\n\na"), "a"))
     42 		error("skip_ws of \\n\\na is not a");
     43 	if (strcmp(skip_ws("\n a"), "a"))
     44 		error("skip_ws of \\n a is not a");
     45 	if (strcmp(skip_ws("\n \ta"), "a"))
     46 		error("skip_ws of \\n \\ta is not a");
     47 	if (strcmp(skip_ws("\n \t"), ""))
     48 		error("skip_ws of \\n \\t is not \"\"");
     49 	if (strcmp(skip_ws(" "), ""))
     50 		error("skip_ws of \" \" is not \"\"");
     51 
     52 	if (strcmp(skip_nonws(""), ""))
     53 		error("skip_nonws of \"\" is not \"\"");
     54 	if (strcmp(skip_nonws("a"), ""))
     55 		error("skip_nonws of a is not \"\"");
     56 	if (strcmp(skip_nonws("\n"), "\n"))
     57 		error("skip_nonws of \\n is not \\n");
     58 	if (strcmp(skip_nonws(" "), " "))
     59 		error("skip_nonws of \" \" is not \" \"");
     60 	if (strcmp(skip_nonws("\t"), "\t"))
     61 		error("skip_nonws of \\t is not \\t");
     62 	if (strcmp(skip_nonws("a\n"), "\n"))
     63 		error("skip_nonws of a\\n is not \\n");
     64 	if (strcmp(skip_nonws("ab"), ""))
     65 		error("skip_nonws of ab is not \"\"");
     66 
     67 	if (!empty_line(""))
     68 		error("empty_line is false for \"\"");
     69 	if (!empty_line("\n\t "))
     70 		error("empty_line is false for \"\\n\\n \"");
     71 	if (!empty_line(" "))
     72 		error("empty_line is false for \" \"");
     73 	if (empty_line("\r"))
     74 		error("empty_line is true for \\r");
     75 
     76 	if (comment_line(""))
     77 		error("comment_line is true for \"\"");
     78 	if (comment_line("\n"))
     79 		error("comment_line is true for \n");
     80 	if (!comment_line("#"))
     81 		error("comment_line is false for #");
     82 	if (!comment_line(" #"))
     83 		error("comment_line is false for \" #\"");
     84 	/* this is what the spec says */
     85 	if (!comment_line("\n#"))
     86 		error("comment_line is false for \\n#");
     87 	if (!comment_line("\t#"))
     88 		error("comment_line is false for \\t#");
     89 
     90 	return EXIT_SUCCESS;
     91 }
     92