📄 testall.c
字号:
/* ----------------------------------------------------------------<Prolog>-
Name: testall.c
Title: Test program for all SFL functions (optimistic version)
Package: Standard Function Library (SFL)
Written: 1997/01/06 iMatix SFL project team <sfl@imatix.com>
Revised: 1999/11/23
Synopsis: Runs tests on all SFL functions. That's the plan, anyhow.
Copyright: Copyright (c) 1996-2000 iMatix Corporation
License: This is free software; you can redistribute it and/or modify
it under the terms of the SFL License Agreement as provided
in the file LICENSE.TXT. This software is distributed in
the hope that it will be useful, but without any warranty.
------------------------------------------------------------------</Prolog>-*/
#include "sfl.h"
void handle_signal (int the_signal)
{
exit (EXIT_FAILURE);
}
/* ------------------------------------------------------------------------ */
void do__resolve_path (char *data)
{
char
*new_path;
new_path = resolve_path (data);
printf (" resolve_path (%s) --> \"%s\"\n", data, new_path);
mem_free (new_path);
new_path = locate_path ("\\root\\", data);
printf (" locate_path (\\root\\ + %s) --> \"%s\"\n", data, new_path);
mem_free (new_path);
}
void test_sfldir (void)
{
puts ("Testing SFLDIR package");
do__resolve_path ("");
do__resolve_path (".");
do__resolve_path ("..");
do__resolve_path ("...");
do__resolve_path ("./");
do__resolve_path ("../");
do__resolve_path (".../");
do__resolve_path ("/./");
do__resolve_path ("/../");
do__resolve_path ("/.../");
do__resolve_path ("a/../");
do__resolve_path ("ab/./");
do__resolve_path ("ab/../");
do__resolve_path ("ab/.../");
do__resolve_path ("/a/../");
do__resolve_path ("/ab/./");
do__resolve_path ("/ab/../");
do__resolve_path ("/ab/.../");
do__resolve_path ("/.");
do__resolve_path ("/..");
do__resolve_path ("/...");
do__resolve_path ("a/..");
do__resolve_path ("ab/.");
do__resolve_path ("ab/..");
do__resolve_path ("ab/...");
do__resolve_path ("/a/..");
do__resolve_path ("/ab/.");
do__resolve_path ("/ab/..");
do__resolve_path ("/ab/...");
do__resolve_path ("/./x");
do__resolve_path ("/../x");
do__resolve_path ("/.../x");
do__resolve_path ("a/../x");
do__resolve_path ("ab/./x");
do__resolve_path ("ab/../x");
do__resolve_path ("ab/.../x");
do__resolve_path ("a/b/./x");
do__resolve_path ("a/b/../x");
do__resolve_path ("a/b/.../x");
do__resolve_path ("a/b/c/./x");
do__resolve_path ("a/b/c/../x");
do__resolve_path ("a/b/c/.../x");
do__resolve_path ("/a/../x");
do__resolve_path ("/ab/./x");
do__resolve_path ("/ab/../x");
do__resolve_path ("/ab/.../x");
do__resolve_path (".name./..is../...okay...");
do__resolve_path ("root/././test/dir");
do__resolve_path ("root/../../test/dir");
do__resolve_path ("root/.../.../test/dir");
do__resolve_path ("a/../x/..");
do__resolve_path ("//a//../x/../");
}
/* ------------------------------------------------------------------------ */
void do__file_is_executable (char *filename)
{
printf ("%s executable? %d\n", filename, file_is_executable (filename));
printf ("%s program? %d\n", filename, file_is_program (filename));
}
void do__file_where (char *filename)
{
char
*full_name;
full_name = file_where ('r', "PATH", filename, NULL);
if (full_name)
printf ("find %s => %s\n", filename, full_name);
}
void test_sflfile (void)
{
puts ("Testing SFLFILE package");
do__file_is_executable ("sflfile.c");
do__file_is_executable ("lr");
do__file_is_executable ("testall");
#if defined (__WINDOWS__)
do__file_is_executable ("testall.exe");
do__file_where ("testall.exe");
do__file_where ("..\\sfl\\testall.exe");
do__file_where ("../sfl/testall.exe");
#elif defined (__UNIX__)
do__file_is_executable ("testall");
do__file_where ("testall");
do__file_where ("..\\sfl\\testall");
do__file_where ("../sfl/testall");
#endif
}
/* ------------------------------------------------------------------------ */
void test_sfltok (void)
{
char
**table,
*result;
int
wordnbr;
SYMTAB
*envtab;
puts ("Testing SFLTOK package");
table = tok_split (" word");
puts ("String after breaking up:");
for (wordnbr = 0; table [wordnbr]; wordnbr++)
printf ("%d: %s\n", wordnbr, table [wordnbr]);
printf ("Table size=%d textsize=%ld\n",
tok_size (table), (long) tok_text_size (table));
tok_free (table);
table = tok_split ("This is a string ding-a-ling-a-ding");
puts ("String after breaking up:");
for (wordnbr = 0; table [wordnbr]; wordnbr++)
printf ("%d: %s\n", wordnbr, table [wordnbr]);
printf ("Table size=%d textsize=%ld\n",
tok_size (table), (long) tok_text_size (table));
table = tok_push (table, "Should come before");
puts ("String after prefixing:");
for (wordnbr = 0; table [wordnbr]; wordnbr++)
printf ("%d: %s\n", wordnbr, table [wordnbr]);
printf ("Table size=%d textsize=%ld\n",
tok_size (table), (long) tok_text_size (table));
tok_free (table);
table = tok_split_rich ("This is a \"string !\" ding-a-ling-a-ding", "\"");
puts ("String after breaking up:");
for (wordnbr = 0; table [wordnbr]; wordnbr++)
printf ("%d: %s\n", wordnbr, table [wordnbr]);
printf ("Table size=%d textsize=%ld\n",
tok_size (table), (long) tok_text_size (table));
tok_free (table);
envtab = env2symb ();
result = tok_subst ("$(PATH)/$(TEMP)/$(NONE)", envtab);
puts (result);
mem_free (result);
result = tok_subst ("Path=$(PATH)--temp=$(TEMP)--none=$(NONE)--", envtab);
puts (result);
mem_free (result);
sym_delete_table (envtab);
mem_assert ();
}
/* ------------------------------------------------------------------------ */
void test_sflini (void)
{
/* Uses testall.ini as input */
SYMTAB
*symtab = NULL;
symtab = ini_dyn_load (NULL, "testall.ini");
ini_dyn_save (symtab, "testall.new");
sym_delete_table (symtab);
mem_assert ();
}
/* ------------------------------------------------------------------------ */
void test_soundex (char *value)
{
printf ("Soundex of %s = %s\n", value, soundexn (value, 5, TRUE));
}
void test_sflstr (void)
{
test_soundex ("fabrique");
test_soundex ("ebri");
test_soundex ("immo");
test_soundex ("poelman");
test_soundex ("wijngaert");
test_soundex ("bvba");
}
/* ------------------------------------------------------------------------ */
void test_sflenv (void)
{
SYMTAB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -