Ticket #10030 (closed defect: invalid)

Opened 2 months ago

Last modified 7 weeks ago

wxConfigBase::Read() returns false "true"

Reported by: pmendl Owned by:
Priority: normal Milestone:
Component: base Version: 2.8.x
Keywords: wxConfigBase Read Cc:
Blocked By: Patch: no
Blocking:

Description

Description: the following piece of code should list "url=<empty>" if key not found for the given entity. However, it lists many "url=" lines (and following processing shows url to be really empty as set to wxEmptyString in object constructor) and no "url=<empty>" line. If I am not missing some obvious thing it seems that wxConfigBase::Read() returns allways "true", even if key does not exist...

class cAbstractEntity
{
	public:
//...
		wxString url;
//...
	protected:
//...
};
//...
        wxFileConfig *conf;
        cAbstractEntity *ae;
//...
        // Other fields read properly, from the proper config path/section here
//...
	if(conf->Read(wxT("URL"), &(ae->url)))
		std::cout << "url=" << ae->url.mb_str() << std::endl;
	else
		std::cout << "url=<empty>" << std::endl;

I am open to any further tests you can see helpfull, just ask.

Change History

Changed 2 months ago by vadz

  • status changed from new to infoneeded_new

Which wxConfig implementation (wxRegConfig, wxFileConfig, ...) are you using? And what is the input, i.e. the config file or registry contents?

Changed 2 months ago by pmendl

  • status changed from infoneeded_new to new

1) Using wxFileConfig as can be seen from conf variable declaration ca in the middle of my code.

2) This is part (the beginning) of the config file content (just information garbled, not the structure):

community=censored
[City1]
URL=www.fake1.na
[City1/A1]
[City1/A1/1]
IP=192.168.1.66
URL=www.fake2.na
# ...

P.S. Just completed this particular feature implementation. Everything works properly, either supported url texts either empty strings are read and detected properly (except of the above described problem).
In fact figured out that I do not need the bool return value for this particular application. Just still feel it dangerous to leave such bugs unreported/uncorrected for some future wxWidgets usage.

Changed 2 months ago by vadz

  • status changed from new to closed
  • resolution set to worksforme

Sorry for failing to notice wxFileConfig mention in the code.

Anyhow, I can't reproduce the bug, here is the patch to the unit test which I added:

Index: tests/config/fileconf.cpp
===================================================================
--- tests/config/fileconf.cpp   (revision 56055)
+++ tests/config/fileconf.cpp   (working copy)
@@ -80,6 +80,7 @@
         CPPUNIT_TEST( DeleteLastGroup );
         CPPUNIT_TEST( DeleteAndRecreateGroup );
         CPPUNIT_TEST( AddToExistingRoot );
+        CPPUNIT_TEST( ReadNonExistent );
     CPPUNIT_TEST_SUITE_END();

     void Path();
@@ -101,6 +102,7 @@
     void DeleteLastGroup();
     void DeleteAndRecreateGroup();
     void AddToExistingRoot();
+    void ReadNonExistent();


     static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
@@ -628,5 +630,24 @@
     );
 }

+void FileConfigTestCase::ReadNonExistent()
+{
+    static const char *confTest =
+        "community=censored\n"
+        "[City1]\n"
+        "URL=www.fake1.na\n"
+        "[City1/A1]\n"
+        "[City1/A1/1]\n"
+        "IP=192.168.1.66\n"
+        "URL=www.fake2.na\n"
+    ;
+
+    wxStringInputStream sis(confTest);
+    wxFileConfig fc(sis);
+
+    wxString url;
+    CPPUNIT_ASSERT( !fc.Read("URL", &url) );
+}
+
 #endif // wxUSE_FILECONFIG

and it passes. Can you please modify it so that it fails?

Thanks in advance (we do value your bug report but we really need a way to reproduce it).

Changed 2 months ago by pmendl

  • status changed from closed to reopened
  • resolution deleted

I am sorry for any inconvenience, but: I do not see any tests/config/ folder in my wxWidgets source files (untared from wxGTK-2.8.9.tar.gz). Did you mean tests/fileconf/fileconftest.cpp ?
This is the list of my tests/ folder:

celkem 232
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 archive
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 arrays
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 datetime
 4 -rw-r--r-- 1 pavel benden   754 15. zář 09.34 dummy.cpp
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 fileconf
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 filekind
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 filename
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 filesys
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 fontmap
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 formatconverter
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 geometry
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 hashes
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 lists
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 longlong
20 -rw-r--r-- 1 pavel benden 17142 15. zář 09.34 makefile.bcc
16 -rw-r--r-- 1 pavel benden 12592 15. zář 09.34 makefile.dmc
20 -rw-r--r-- 1 pavel benden 17396 15. zář 09.34 makefile.dms
16 -rw-r--r-- 1 pavel benden 15030 15. zář 09.34 makefile.gcc
20 -rw-r--r-- 1 pavel benden 19629 15. zář 09.34 Makefile.in
20 -rw-r--r-- 1 pavel benden 20151 15. zář 09.34 makefile.vc
20 -rw-r--r-- 1 pavel benden 17427 15. zář 09.34 makefile.wat
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 mbconv
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 regex
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 scopeguard
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 streams
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 strings
 4 -rw-r--r-- 1 pavel benden  3115 15. zář 09.34 test.bkl
 8 -rw-r--r-- 1 pavel benden  5051 15. zář 09.34 test.cpp
 4 -rw-r--r-- 1 pavel benden   150 15. zář 09.34 testdata.fc
 4 -rw-r--r-- 1 pavel benden   261 15. zář 09.34 testprec.h
 4 drwxr-xr-x 2 pavel benden  4096 15. zář 09.34 uris

Being software developer myself I fully understand the need to reproduce bug "on the table" ;-). I will surely try to stay with you till the end, just excuse in advance if I will sometimes delay my response (even several days) as clients has allways priority, you know.

Changed 2 months ago by vadz

  • status changed from reopened to infoneeded_new

Sorry, I forgot it was added in the trunk only. The file contents can be seen here but you can also try reproducing the bug in the minimal sample or in a minimal console program using the code like above.

Thanks!

Changed 7 weeks ago by pmendl

  • status changed from infoneeded_new to closed
  • resolution set to invalid

Well, however it sounds silly, the bug disappeared completely. After trying to reproduce above described behaviour on the simplified cut from the original code and getting correct results all the time I turned back to original code, uncommented the troublesome part and - believe or not - got absolutely correct results now.

I could only speculate about several restarts/some package installations etc. being involved, however it makes no sense. The bug vanished and only if it reappears, I'll get back with new information.

Thank for your interrest anyways and sorry to disturb.

Note: See TracTickets for help on using tickets.