lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [6052] Implement rectified test specification


From: Greg Chicares
Subject: [lmi-commits] [6052] Implement rectified test specification
Date: Sun, 07 Dec 2014 01:57:17 +0000

Revision: 6052
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6052
Author:   chicares
Date:     2014-12-07 01:57:16 +0000 (Sun, 07 Dec 2014)
Log Message:
-----------
Implement rectified test specification

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/objects.make
    lmi/trunk/workhorse.make
    lmi/trunk/wx_test_about_version.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2014-12-06 20:04:21 UTC (rev 6051)
+++ lmi/trunk/ChangeLog 2014-12-07 01:57:16 UTC (rev 6052)
@@ -34759,3 +34759,11 @@
 Simplify thanks to a welcome wx enhancement. See:
   http://lists.nongnu.org/archive/html/lmi/2014-12/msg00013.html
 
+20141207T0157Z <address@hidden> [516]
+
+  objects.make
+  workhorse.make
+  wx_test_about_version.cpp
+Implement rectified test specification. See:
+  http://lists.nongnu.org/archive/html/lmi/2014-12/msg00030.html
+

Modified: lmi/trunk/objects.make
===================================================================
--- lmi/trunk/objects.make      2014-12-06 20:04:21 UTC (rev 6051)
+++ lmi/trunk/objects.make      2014-12-07 01:57:16 UTC (rev 6052)
@@ -355,6 +355,7 @@
   main_wx.o \
 
 wx_test_objects := \
+  $(boost_regex_objects) \
   main_wx_test.o \
   wx_test_about_version.o \
   wx_test_benchmark_census.o \

Modified: lmi/trunk/workhorse.make
===================================================================
--- lmi/trunk/workhorse.make    2014-12-06 20:04:21 UTC (rev 6051)
+++ lmi/trunk/workhorse.make    2014-12-07 01:57:16 UTC (rev 6052)
@@ -857,7 +857,7 @@
 wx_new$(SHREXT): wx_new.o
 
 wx_test$(EXEEXT): lmi_so_attributes := -DLMI_USE_SO
-wx_test$(EXEEXT): EXTRA_LDFLAGS := $(wx_ldflags)
+wx_test$(EXEEXT): EXTRA_LDFLAGS := $(wx_ldflags) 
-Wl,--allow-multiple-definition
 wx_test$(EXEEXT): $(wx_test_objects) skeleton$(SHREXT) liblmi$(SHREXT)
 
 # TODO ?? This needs a corresponding test target.

Modified: lmi/trunk/wx_test_about_version.cpp
===================================================================
--- lmi/trunk/wx_test_about_version.cpp 2014-12-06 20:04:21 UTC (rev 6051)
+++ lmi/trunk/wx_test_about_version.cpp 2014-12-07 01:57:16 UTC (rev 6052)
@@ -27,13 +27,20 @@
 #endif
 
 #include "assert_lmi.hpp"
+#include "calendar_date.hpp"
 #include "wx_test_case.hpp"
 #include "version.hpp"
 
 #include <wx/dialog.h>
+#include <wx/html/htmlwin.h>
+#include <wx/log.h>
 #include <wx/testing.h>
 #include <wx/uiaction.h>
 
+#include <boost/regex.hpp>
+
+#include <climits>                      // INT_MAX
+
 /// Validate version string (timestamp) from "About" dialog title.
 ///
 /// Test that the version string matches the timestamp specified in
@@ -57,6 +64,111 @@
 /// license's dialog box is scrollable--to guard against this problem:
 ///   http://lists.nongnu.org/archive/html/lmi/2010-01/msg00001.html
 
+namespace
+{
+
+// Convert a string known to consist of just 4 digits to a number.
+//
+// This function contains LMI_ASSERT() checks but they should be never
+// triggered if the preconditions are filled as any string of 4 digits can be
+// converted to an int value.
+int year_from_string(wxString const& s)
+{
+    unsigned long year;
+
+    LMI_ASSERT(s.ToCULong(&year));
+    LMI_ASSERT(year < INT_MAX);
+
+    return static_cast<int>(year);
+}
+
+// Find the last copyright year in the given HTML license notices text.
+//
+// May throw if the input doesn't conform to the expectations.
+int extract_last_copyright_year(wxString const& html)
+{
+    // Find the line starting with "Copyright".
+    wxArrayString const lines = wxSplit(html ,'\n' ,'\0');
+
+    wxString line;
+    for(wxArrayString::const_iterator i = lines.begin(); i != lines.end(); ++i)
+        {
+        if(i->StartsWith("Copyright"))
+            {
+            LMI_ASSERT_WITH_MSG
+                (line.empty()
+                ,"Unexpectedly found more than one copyright line in the "
+                 "license notices text"
+                );
+
+            line = *i;
+            }
+        }
+
+    LMI_ASSERT_WITH_MSG
+        (!line.empty()
+        ,"Copyright line not found in the license notices text"
+        );
+
+    // We suppose that we have a sequence of comma-separated (4 digit, let
+    // someone else worry about Y10K problem) years and so the year we are
+    // interested in is just the last one of them.
+    //
+    // Notice also the use of utf8_str() to ensure that conversion from
+    // wxString never fails (it could if the string contained non-ASCII
+    // characters such as the copyright sign), while avoiding the use of wide
+    // char boost::regex functions that are not available under all platforms
+    // and notably not with MinGW 3.4. As we are only interested in matching
+    // ASCII characters such as digits, using UTF-8 is safe even though
+    // boost::regex has no real support for it.
+    std::string const line_utf8(line.utf8_str());
+    boost::smatch m;
+    LMI_ASSERT_WITH_MSG
+        (boost::regex_search
+            (line_utf8
+            ,m
+            ,boost::regex("(?:\\d{4}, )+(\\d{4})")
+            )
+        ,"Copyright line \"" + line + "\" doesn't contain copyright years"
+        );
+
+    return year_from_string(wxString(m[1]));
+}
+
+// Find the only wxHtmlWindow inside the given dialog.
+//
+// Throws if there are none, or more than one, windows of wxHtmlWindow type in
+// the dialog. The dialog name is only used for diagnostic purposes.
+wxHtmlWindow* find_html_window(wxWindow* parent, std::string const& 
dialog_name)
+{
+    wxHtmlWindow* html_win = 0;
+    wxWindowList const& wl = parent->GetChildren();
+    for(wxWindowList::const_iterator i = wl.begin(); i != wl.end(); ++i)
+        {
+        wxHtmlWindow* const maybe_html_win = dynamic_cast<wxHtmlWindow*>(*i);
+        if(maybe_html_win)
+            {
+            LMI_ASSERT_WITH_MSG
+                (!html_win
+                ,"Unexpectedly found more than one wxHtmlWindow in "
+                 "the " + dialog_name + " dialog"
+                );
+
+            html_win = maybe_html_win;
+            }
+        }
+
+    LMI_ASSERT_WITH_MSG
+        (html_win
+        ,"wxHtmlWindow showing the license notices not found in "
+         "the " + dialog_name + " dialog"
+        );
+
+    return html_win;
+}
+
+} // anonymous namespace
+
 LMI_WX_TEST_CASE(about_dialog_version)
 {
     struct expect_about_dialog : public wxExpectModalBase<wxDialog>
@@ -64,16 +176,78 @@
         virtual int OnInvoked(wxDialog* d) const
             {
             LMI_ASSERT(0 != d);
-            LMI_ASSERT(d->GetTitle().EndsWith(LMI_VERSION));
+
+            // Extract the last word of the dialog title.
+            wxString const last_word = d->GetTitle().AfterLast(' ');
+            wxLogMessage("About dialog version string is \"%s\".", last_word);
+            LMI_ASSERT_EQUAL(last_word, LMI_VERSION);
+
+            // Find the wxHtmlWindow showing the license notices.
+            wxHtmlWindow* const
+                license_notices_win = find_html_window(d, "about");
+
+            // Check that the years in the copyright, license notices and
+            // version string are all the same.
+            int const copyright_year =
+                extract_last_copyright_year(license_notices_win->ToText());
+
+            LMI_ASSERT_EQUAL(copyright_year, today().year());
+
+            int const version_year = year_from_string(wxString(LMI_VERSION, 
4));
+            LMI_ASSERT_EQUAL(version_year, copyright_year);
+
+            // Finally bring up the dialog showing the license itself: for this
+            // we first need to show this dialog itself.
+            d->Show();
+            wxYield();
+
+            // And then press the default button in it which opens the license.
+            struct expect_license_dialog : public wxExpectModalBase<wxDialog>
+            {
+                virtual int OnInvoked(wxDialog* d) const
+                    {
+                    wxHtmlWindow* const
+                        license_win = find_html_window(d, "license");
+
+                    // This is a rather indirect -- because testing this
+                    // directly is not easily possible -- test of the scrollbar
+                    // presence in the license window: we try to scroll it and
+                    // expect it to have a result, as the license text is known
+                    // to be long enough to not fit on a single page, even in
+                    // high vertical resolutions.
+                    //
+                    // The first test just checks that the return value of
+                    // LineXXX() methods makes sense: it should return false if
+                    // no scrolling is possible. The second test checks that
+                    // scrolling down does actually work.
+                    LMI_ASSERT_WITH_MSG
+                        (!license_win->LineUp()
+                        ,"License window unexpectedly scrolled up"
+                        );
+
+                    LMI_ASSERT_WITH_MSG
+                        (license_win->LineDown()
+                        ,"License window didn't scroll down"
+                        );
+
+                    return wxID_OK;
+                    }
+            };
+
+            wxUIActionSimulator z;
+            z.Char(WXK_RETURN);
+            wxTEST_DIALOG
+                (wxYield()
+                ,expect_license_dialog()
+                );
+
             return wxID_OK;
             }
     };
 
     wxUIActionSimulator z;
-    z.KeyDown('h', wxMOD_ALT);
-    z.KeyUp  ('h', wxMOD_ALT);
-    z.KeyDown('a'           );
-    z.KeyUp  ('a'           );
+    z.Char('h', wxMOD_ALT);
+    z.Char('a'           );
     wxTEST_DIALOG
         (wxYield()
         ,expect_about_dialog()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]