Hi!
Here comes patch that removes messcat_src.txt. Instead of trying to find
it the test now creates it on the fly. Also the code is cleaned up a
little.
Signed-off-by: Cyril Hrubis [email protected]
--
Cyril Hrubis
[email protected]
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
index c98e37b..50a23a9 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
@@ -21,7 +21,7 @@
* The steps are:
-* -> Create a message catalog file from the "messcat_src.txt" file
+* -> Create a message catalog file from the file
* -> Open this catalog
* -> fork
* -> Check that the child can read from the message catalog.
@@ -34,186 +34,132 @@
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
#define _POSIX_C_SOURCE 200112L
-/********************************************************************************************/
-/****************************** standard includes *****************************************/
-/********************************************************************************************/
#include <pthread.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <sys/wait.h>
- #include <errno.h>
+#include <errno.h>
#include <nl_types.h>
-/********************************************************************************************/
-/****************************** Test framework *****************************************/
-/********************************************************************************************/
#include "testfrmw.h"
- #include "testfrmw.c"
-/* This header is responsible for defining the following macros:
- * UNRESOLVED(ret, descr);
- * where descr is a description of the error and ret is an int (error code for example)
- * FAILED(descr);
- * where descr is a short text saying why the test has failed.
- * PASSED();
- * No parameter.
- *
- * Both three macros shall terminate the calling process.
- * The testcase shall not terminate in any other maneer.
- *
- * The other file defines the functions
- * void output_init()
- * void output(char * string, ...)
- *
- * Those may be used to output information.
- */
-
-/********************************************************************************************/
-/********************************** Configuration ******************************************/
-/********************************************************************************************/
+#include "testfrmw.c"
+
#ifndef VERBOSE
#define VERBOSE 1
#endif
-#define PATH_OFFSET "conformance/interfaces/fork/"
-
-/********************************************************************************************/
-/*********************************** Test case *****************************************/
-/********************************************************************************************/
+#define MESSCAT_IN "messcat.txt"
+#define MESSCAT_OUT "messcat.cat"
-void read_catalog(nl_catd cat, char * who)
+void read_catalog(nl_catd cat, char *who)
{
- char * msg = NULL;
+ char *msg = NULL;
int i, j;
errno = 0;
#if VERBOSE > 0
-
output("Reading the message catalog from %s...\n", who);
#endif
- for (i = 1; i <= 2; i++)
- {
- for (j = 1; j <= 2; j++)
- {
+ for (i = 1; i <= 2; i++) {
+ for (j = 1; j <= 2; j++) {
+
msg = catgets(cat, i, j, "not found");
if (errno != 0)
- {
UNRESOLVED(errno, "catgets returned an error");
- }
-
#if VERBOSE > 1
output("set %i msg %i: %s\n", i, j, msg);
-
#endif
-
}
}
#if VERBOSE > 0
output("Message catalog read successfully in %s\n", who);
-
#endif
}
-/* The main test function. */
+static char *messcat_in =
+"$set 1\n1 First sentence\n2 Second sentence\n"
+"$set 2\n1 First translated sentence\n2 Second translated sentence\n";
+
+static int create_catalog(void)
+{
+ FILE *f = fopen(MESSCAT_IN, "w");
+
+ if (f == NULL)
+ return 1;
+
+ if (fputs(messcat_in, f) <= 0)
+ return 1;
+
+ if (fclose(f))
+ return 1;
+
+ return 0;
+}
+
int main(int argc, char * argv[])
{
int ret, status;
pid_t child, ctl;
-
nl_catd messcat;
- /* Initialize output */
output_init();
-
/* Generate the message catalog file from the text sourcefile */
+ if (system(NULL)) {
+
+ if (create_catalog() != 0) {
+ UNRESOLVED(errno, "Can't create "MESSCAT_IN);
+ }
- if (system(NULL))
- {
- ret = system("gencat mess.cat " PATH_OFFSET "messcat_src.txt");
+ ret = system("gencat "MESSCAT_OUT" "MESSCAT_IN);
if (ret != 0)
- {
- output("Unable to find messcat_src.txt in standard directory %s\n", PATH_OFFSET);
- output("Trying local dir\n");
- ret = system("gencat mess.cat messcat_src.txt");
-
- if (ret != 0)
- {
- output("Could not find the source file for message catalog.\n" \
- "You may need to execute gencat yourself.\n");
- }
- }
+ output("Could not find the source file for message catalog.\n" \
+ "You may need to execute gencat yourself.\n");
}
- /* Try opening the message catalog file */
- messcat = catopen("./mess.cat", 0);
+ messcat = catopen("./"MESSCAT_OUT, 0);
if (messcat == (nl_catd) -1)
- {
- UNRESOLVED(errno, "Could not open ./mess.cat. You may need to do a gencat before executing this testcase");
- }
+ UNRESOLVED(errno, "Could not open ./"MESSCAT_OUT);
- /* Read the message catalog */
read_catalog(messcat, "parent");
-
- /* Create the child */
child = fork();
if (child == -1)
- {
UNRESOLVED(errno, "Failed to fork");
- }
- /* child */
- if (child == 0)
- {
+ if (child == 0) {
read_catalog(messcat, "child");
-
- /* We're done */
exit(PTS_PASS);
}
- /* Parent joins the child */
ctl = waitpid(child, &status, 0);
if (ctl != child)
- {
UNRESOLVED(errno, "Waitpid returned the wrong PID");
- }
if ((!WIFEXITED(status)) || (WEXITSTATUS(status) != PTS_PASS))
- {
FAILED("Child exited abnormally");
- }
- /* We can now clean up the message catalog file */
ret = catclose(messcat);
if (ret != 0)
- {
UNRESOLVED(errno, "Failed to close the message catalog");
- }
- /* Try removing the message catalog file */
- system("rm -f mess.cat");
+ system("rm -f "MESSCAT_IN" "MESSCAT_OUT);
- /* Test passed */
#if VERBOSE > 0
-
output("Test passed\n");
-
#endif
-
PASSED;
}
-
-
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/fork/messcat_src.txt b/testcases/open_posix_testsuite/conformance/interfaces/fork/messcat_src.txt
deleted file mode 100644
index e0067d9..0000000
--- a/testcases/open_posix_testsuite/conformance/interfaces/fork/messcat_src.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-$ Copyright (c) 2004, Bull S.A.. All rights reserved.
-$ Created by: Sebastien Decugis
-$
-$ This program is free software; you can redistribute it and/or modify it
-$ under the terms of version 2 of the GNU General Public License as
-$ published by the Free Software Foundation.
-$
-$ This program is distributed in the hope that it would be useful, but
-$ WITHOUT ANY WARRANTY; without even the implied warranty of
-$ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-$
-$ You should have received a copy of the GNU General Public License along
-$ with this program; if not, write the Free Software Foundation, Inc., 59
-$ Temple Place - Suite 330, Boston MA 02111-1307, USA.
-$
-$
-$ This file is part of the 7-1.c test case for the fork() routine.
-
-$set 1 Message set for OPTS fork test case, English language
-1 This is the first message
-2 And this is the second
-
-$set 2 Message set for OPTS fork test case, French language
-1 Voici le premier message
-2 Et voilĂ le second
-
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list