[geos-commits] r3768 - in trunk: . include/geos/io src/io tests/unit tests/unit/io

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Feb 25 02:34:11 PST 2013


Author: strk
Date: 2013-02-25 02:34:10 -0800 (Mon, 25 Feb 2013)
New Revision: 3768

Added:
   trunk/tests/unit/io/WriterTest.cpp
Modified:
   trunk/NEWS
   trunk/include/geos/io/Writer.h
   trunk/src/io/Writer.cpp
   trunk/tests/unit/Makefile.am
Log:
io::Writer: take and give strings by const ref, use .append, testcase

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2013-02-21 10:29:19 UTC (rev 3767)
+++ trunk/NEWS	2013-02-25 10:34:10 UTC (rev 3768)
@@ -16,7 +16,8 @@
   - Signature of most functions taking an IntersectionMatrix changed
     to take it by reference rather than pointer.
   - GraphComponent::label is now a Label value (from a pointer)
-  -e NodedSegmentString takes ownership of CoordinateSenuence now
+  - NodedSegmentString takes ownership of CoordinateSenuence now
+  - io::Writer's toString() returns by const ref, write() takes a const ref
 - Bug fixes / improvements
   - Improve Buffer robustness by reducing input precision on topology
     exception (#605)

Modified: trunk/include/geos/io/Writer.h
===================================================================
--- trunk/include/geos/io/Writer.h	2013-02-21 10:29:19 UTC (rev 3767)
+++ trunk/include/geos/io/Writer.h	2013-02-25 10:34:10 UTC (rev 3768)
@@ -36,8 +36,8 @@
 public:
 	Writer();
 	~Writer();
-	void write(std::string txt);
-	std::string toString();
+	void write(const std::string& txt);
+	const std::string& toString();
 private:
 	std::string str;
 };

Modified: trunk/src/io/Writer.cpp
===================================================================
--- trunk/src/io/Writer.cpp	2013-02-21 10:29:19 UTC (rev 3767)
+++ trunk/src/io/Writer.cpp	2013-02-25 10:34:10 UTC (rev 3768)
@@ -27,7 +27,6 @@
 
 Writer::Writer()
 {
-	str="";
 }
 
 Writer::~Writer()
@@ -35,12 +34,12 @@
 }
 
 void
-Writer::write(string txt)
+Writer::write(const std::string& txt)
 {
-	str+=txt;
+	str.append(txt);
 }
 
-string
+const std::string&
 Writer::toString()
 {
 	return str;

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2013-02-21 10:29:19 UTC (rev 3767)
+++ trunk/tests/unit/Makefile.am	2013-02-25 10:34:10 UTC (rev 3768)
@@ -71,6 +71,7 @@
 	io/WKBWriterTest.cpp \
 	io/WKTReaderTest.cpp \
 	io/WKTWriterTest.cpp \
+	io/WriterTest.cpp \
 	linearref/LengthIndexedLineTest.cpp \
 	noding/BasicSegmentStringTest.cpp \
 	noding/NodedSegmentStringTest.cpp \

Added: trunk/tests/unit/io/WriterTest.cpp
===================================================================
--- trunk/tests/unit/io/WriterTest.cpp	                        (rev 0)
+++ trunk/tests/unit/io/WriterTest.cpp	2013-02-25 10:34:10 UTC (rev 3768)
@@ -0,0 +1,50 @@
+// 
+// Test Suite for geos::io::Writer
+
+// tut
+#include <tut.hpp>
+// geos
+#include <geos/io/Writer.h>
+// std
+#include <sstream>
+#include <string>
+#include <memory>
+
+namespace tut
+{
+	//
+	// Test Group
+	//
+
+	// dummy data, not used
+	struct test_writer_data
+	{
+		test_writer_data()
+    {
+    }
+	};
+
+	typedef test_group<test_writer_data> group;
+	typedef group::object object;
+
+	group test_writer_group("geos::io::Writer");
+
+
+	//
+	// Test Cases
+	//
+
+	template<>
+	template<>
+	void object::test<1>()
+	{         
+    geos::io::Writer writer;
+
+    writer.write("Hello ");
+    writer.write("World!");
+    ensure_equals(writer.toString(), "Hello World!");
+  }
+
+} // namespace tut
+
+



More information about the geos-commits mailing list