Unit test for src/util/os_path.c
This commit was SVN r1156.
Этот коммит содержится в:
родитель
3ce1b9852b
Коммит
bc8330fb7a
@ -7,6 +7,7 @@ include $(top_srcdir)/config/Makefile.options
|
|||||||
AM_CPPFLAGS = -I$(top_srcdir)/test/support -DLAM_ENABLE_DEBUG_OVERRIDE=1
|
AM_CPPFLAGS = -I$(top_srcdir)/test/support -DLAM_ENABLE_DEBUG_OVERRIDE=1
|
||||||
|
|
||||||
noinst_PROGRAMS = \
|
noinst_PROGRAMS = \
|
||||||
|
ompi_os_path \
|
||||||
lam_argv
|
lam_argv
|
||||||
|
|
||||||
lam_argv_SOURCES = lam_argv.c
|
lam_argv_SOURCES = lam_argv.c
|
||||||
@ -23,3 +24,18 @@ lam_argv_LDADD = \
|
|||||||
$(top_builddir)/test/support/libsupport.la
|
$(top_builddir)/test/support/libsupport.la
|
||||||
lam_argv_DEPENDENCIES = $(lam_argv_LDADD)
|
lam_argv_DEPENDENCIES = $(lam_argv_LDADD)
|
||||||
|
|
||||||
|
ompi_os_path_SOURCES = ompi_os_path.c
|
||||||
|
ompi_os_path_LDADD = \
|
||||||
|
$(top_builddir)/src/util/sys_info.lo \
|
||||||
|
$(top_builddir)/src/lfc/lam_object.lo \
|
||||||
|
$(top_builddir)/src/mem/malloc.lo \
|
||||||
|
$(top_builddir)/src/util/output.lo \
|
||||||
|
$(top_builddir)/src/util/argv.lo \
|
||||||
|
$(top_builddir)/src/util/strncpy.lo \
|
||||||
|
$(top_builddir)/src/threads/mutex.lo \
|
||||||
|
$(top_builddir)/src/threads/mutex_pthread.lo \
|
||||||
|
$(top_builddir)/src/threads/mutex_spinlock.lo \
|
||||||
|
$(top_builddir)/src/threads/mutex_spinwait.lo \
|
||||||
|
$(top_builddir)/src/util/os_path.lo \
|
||||||
|
$(top_builddir)/test/support/libsupport.la
|
||||||
|
ompi_os_path_DEPENDENCIES = $(lam_argv_LDADD)
|
||||||
|
175
test/util/ompi_os_path.c
Обычный файл
175
test/util/ompi_os_path.c
Обычный файл
@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
* $HEADER$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
#include "lam_config.h"
|
||||||
|
#include "util/sys_info.h"
|
||||||
|
#include "util/os_path.h"
|
||||||
|
|
||||||
|
static bool test1(void); /* trivial answer test */
|
||||||
|
static bool test2(void); /* relative path test */
|
||||||
|
static bool test3(void); /* absolute path test */
|
||||||
|
static bool test4(void); /* missing path separator test */
|
||||||
|
static bool test5(void); /* very long path name test */
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
bool test1f, test2f, test3f, test4f, test5f;
|
||||||
|
|
||||||
|
test1f = test2f = test3f = test4f = test5f = false;
|
||||||
|
|
||||||
|
/* All done */
|
||||||
|
|
||||||
|
if (test1()) {
|
||||||
|
printf("test1 passed\n");
|
||||||
|
test1f = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test2()) {
|
||||||
|
printf("test2 passed\n");
|
||||||
|
test2f = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test3()) {
|
||||||
|
printf("test3 passed\n");
|
||||||
|
test3f = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test4()) {
|
||||||
|
printf("test4 passed\n");
|
||||||
|
test4f = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test5()) {
|
||||||
|
printf("test5 passed\n");
|
||||||
|
test5f = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test1f && test2f && test3f && test4f && test5f) {
|
||||||
|
printf("test succeeded\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("test failed\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool test1(void)
|
||||||
|
{
|
||||||
|
char *out;
|
||||||
|
|
||||||
|
/* Test trivial functionality. Program should return "." when called in relative
|
||||||
|
* mode, and the separator character when called in absolute mode. */
|
||||||
|
|
||||||
|
if (NULL != (out = ompi_os_path(true,NULL))) {
|
||||||
|
if (0 != strcmp(".", out))
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
if (NULL != (out = ompi_os_path(false,NULL))) {
|
||||||
|
if (0 != strcmp(ompi_system_info.path_sep, out))
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool test2(void)
|
||||||
|
{
|
||||||
|
char *out;
|
||||||
|
char *a[] = { "aaa", "bbb", "ccc", NULL };
|
||||||
|
|
||||||
|
if (NULL == ompi_system_info.path_sep) {
|
||||||
|
printf("test2 cannot be run\n");
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Construct a relative path name and see if it comes back correctly. Check multiple depths. */
|
||||||
|
out = strdup(".");
|
||||||
|
out = strcat(out, ompi_system_info.path_sep);
|
||||||
|
out = strcat(out, a[0]);
|
||||||
|
if (0 != strcmp(out, ompi_os_path(true, a[0], NULL)))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
out = strcat(out, ompi_system_info.path_sep);
|
||||||
|
out = strcat(out, a[1]);
|
||||||
|
if (0 != strcmp(out, ompi_os_path(true, a[0], a[1], NULL)))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
out = strcat(out, ompi_system_info.path_sep);
|
||||||
|
out = strcat(out, a[2]);
|
||||||
|
if (0 != strcmp(out, ompi_os_path(true, a[0], a[1], a[2], NULL)))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool test3(void)
|
||||||
|
{
|
||||||
|
char *out;
|
||||||
|
char *a[] = { "aaa", "bbb", "ccc", NULL };
|
||||||
|
|
||||||
|
if (NULL == ompi_system_info.path_sep) {
|
||||||
|
printf("test3 cannot be run\n");
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Same as prior test, only with absolute path name */
|
||||||
|
out = strdup(ompi_system_info.path_sep);
|
||||||
|
out = strcat(out, a[0]);
|
||||||
|
if (0 != strcmp(out, ompi_os_path(false, a[0], NULL)))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
out = strcat(out, ompi_system_info.path_sep);
|
||||||
|
out = strcat(out, a[1]);
|
||||||
|
if (0 != strcmp(out, ompi_os_path(false, a[0], a[1], NULL)))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
out = strcat(out, ompi_system_info.path_sep);
|
||||||
|
out = strcat(out, a[2]);
|
||||||
|
if (0 != strcmp(out, ompi_os_path(false, a[0], a[1], a[2], NULL)))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool test4(void)
|
||||||
|
{
|
||||||
|
char a[MAXPATHLEN + 10];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (NULL == ompi_system_info.path_sep) {
|
||||||
|
printf("test4 cannot be run\n");
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i< MAXPATHLEN+5; i++) {
|
||||||
|
a[i] = 'a';
|
||||||
|
}
|
||||||
|
if (NULL != ompi_os_path(false, a, NULL)) {
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool test5(void)
|
||||||
|
{
|
||||||
|
/* test to ensure the program doesn't bomb when no separator is found.
|
||||||
|
* Program should try to find one, then return NULL if it can't */
|
||||||
|
|
||||||
|
if (NULL != ompi_system_info.path_sep) {
|
||||||
|
free(ompi_system_info.path_sep);
|
||||||
|
ompi_system_info.path_sep = NULL;
|
||||||
|
}
|
||||||
|
return(test1());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
x
Ссылка в новой задаче
Block a user