]> granicus.if.org Git - flex/commitdiff
add unit test for c++ with yywrap
authorWill Estes <wlestes@users.sourceforge.net>
Fri, 20 Oct 2006 17:10:50 +0000 (17:10 +0000)
committerWill Estes <wlestes@users.sourceforge.net>
Fri, 20 Oct 2006 17:10:50 +0000 (17:10 +0000)
NEWS
configure.in
tests/Makefile.am
tests/descriptions
tests/test-c++-yywrap/.cvsignore [new file with mode: 0644]
tests/test-c++-yywrap/Makefile.am [new file with mode: 0644]
tests/test-c++-yywrap/scanner.l [new file with mode: 0644]
tests/test-c++-yywrap/test.input [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 78622625222953664e2c351dfce100cbfcf14219..4a72d2a3b769b6ac35c0b0cd1bf8b7a63a97500f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ changes between releases of flex.
 See the file COPYING for copying conditions.
 
 * after version 2.5.33
+
+* added new unit test for c++ and yywrap
+
 ** portability fixes to some unit tests
 
 ** new ca,  vi, ga, nl translations from the translation project
index 03fc35011ebf605c7caae9d4281e775b3b22b2c2..16c995c3a208591b8e0400058a5389469cc21e18 100644 (file)
@@ -149,6 +149,7 @@ tests/test-rescan-r/Makefile
 tests/test-quotes/Makefile
 tests/test-ccl/Makefile
 tests/test-extended/Makefile
+tests/test-c++-yywrap/Makefile
 dnl --new-test-here-- This line is processed by tests/create-test.
 )
 
index c9d970daf1c9d8687a631c25ec2195e76907e925..744761a38740de430e43adef576096ed85f4c026 100644 (file)
@@ -26,6 +26,7 @@ dist_noinst_SCRIPTS = \
        create-test
 
 DIST_SUBDIRS = \
+       test-c++-yywrap \
        test-extended \
        test-ccl \
        test-quotes \
@@ -72,6 +73,7 @@ DIST_SUBDIRS = \
        test-table-opts
 
 SUBDIRS = \
+       test-c++-yywrap \
        test-extended \
        test-ccl \
        test-quotes \
index 9bf891a0a16613e535b4a3cc33990e843d963bf5..b263bbb716bb85c29de3c38d9dd63ba87f26c4b2 100644 (file)
@@ -44,3 +44,4 @@ string-r              - Scan strings, reentrant.
 table-opts            - Try every table compression option.
 top                   - Test %top directive.
 yyextra               - Test yyextra.
+c++-yywrap            - test yywrap in c++ scanner
diff --git a/tests/test-c++-yywrap/.cvsignore b/tests/test-c++-yywrap/.cvsignore
new file mode 100644 (file)
index 0000000..31ef089
--- /dev/null
@@ -0,0 +1,6 @@
+Makefile
+Makefile.in
+scanner.cpp
+OUTPUT
+.deps
+test-c++-yywrap
diff --git a/tests/test-c++-yywrap/Makefile.am b/tests/test-c++-yywrap/Makefile.am
new file mode 100644 (file)
index 0000000..2929f28
--- /dev/null
@@ -0,0 +1,45 @@
+# This file is part of flex.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+
+# Neither the name of the University nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE.
+
+
+FLEX = $(top_builddir)/flex
+
+EXTRA_DIST = scanner.l test.input
+CLEANFILES = scanner.cpp scanner.h test-c++-yywrap OUTPUT $(OBJS)
+OBJS = scanner.o
+
+AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir)
+LFLAGS = -+
+#LDFLAGS = 
+
+testname = test-c++-yywrap
+
+scanner.cpp: $(srcdir)/scanner.l
+       $(FLEX) $(LFLAGS) $<
+
+$(testname)$(EXEEXT): $(OBJS)
+       $(CXX) -o $@ $(LDFLAGS) $(OBJS)
+
+test: $(testname)$(EXEEXT)
+       ./$(testname)$(EXEEXT) $(srcdir)/test.input $(srcdir)/test.input $(srcdir)/test.input
+
+.cpp.o:
+       $(CXX) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $<
diff --git a/tests/test-c++-yywrap/scanner.l b/tests/test-c++-yywrap/scanner.l
new file mode 100644 (file)
index 0000000..433ad08
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * This file is part of flex.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+%{
+
+#include "config.h"
+#include <fstream>
+
+%}
+
+%option 8bit outfile="scanner.cpp" prefix="test"
+%option nounput nomain
+%option warn c++
+
+
+%%
+
+.              { }
+
+%%
+
+#define MAX_FILES 10
+
+char *files[MAX_FILES] = { 0 };
+int filecounter = 0;
+
+int testFlexLexer::yywrap()
+{
+    if (filecounter-- > 0) {
+        std::cout << "NOW WRAPPING TO READ " << files[filecounter] << std::endl;
+        std::ifstream *ifs = new std::ifstream(files[filecounter]);
+        switch_streams(ifs);
+        return 0;
+    }
+    return 1;
+}
+
+int
+main (int argc, char *argv[])
+{
+    for (int i = 1; i < argc && i <= MAX_FILES; i++) {
+        files[i-1] = argv[i];
+       filecounter++;
+    }
+    testFlexLexer* f = new testFlexLexer;
+    f->yywrap();
+    f->yylex();
+    std::cout << "TEST RETURNING OK." << std::endl;
+    return 0;
+}
diff --git a/tests/test-c++-yywrap/test.input b/tests/test-c++-yywrap/test.input
new file mode 100644 (file)
index 0000000..7288a40
--- /dev/null
@@ -0,0 +1,2 @@
+0000 foo 1111 foo 0000 bar
+0000 foo 1111 foo 0000 bar