aboutsummaryrefslogtreecommitdiffstats
path: root/tests/libsample
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-12-29 10:09:58 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-12-29 15:42:18 -0300
commit9f79c3de8192c4ce5f0ae86687d3ece2196323ba (patch)
tree742281d9a54b01c1e9888b311878c6a8604c57ef /tests/libsample
parent731a68999274ab58fb35f3d3238f713fbf91c878 (diff)
Adds test for modified function using type system template.
The new test adds a "toInt(bool* ok = 0, int base = 10)" method to Str class. The modification uses a type system template function that uses the variable "%2" to reference the "base" argument; in the case when the thing is called without parameters "%2" should be replaced by "10" instead of a converted C++ variable name. Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Diffstat (limited to 'tests/libsample')
-rw-r--r--tests/libsample/str.cpp25
-rw-r--r--tests/libsample/str.h2
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/libsample/str.cpp b/tests/libsample/str.cpp
index bd7076087..87e1145ce 100644
--- a/tests/libsample/str.cpp
+++ b/tests/libsample/str.cpp
@@ -93,6 +93,31 @@ Str::cstring() const
return m_str.c_str();
}
+int
+Str::toInt(bool* ok, int base) const
+{
+ bool my_ok;
+ int result = 0;
+ istringstream conv(m_str);
+ switch (base) {
+ case 8:
+ conv >> std::oct >> result;
+ break;
+ case 10:
+ conv >> std::dec >> result;
+ break;
+ case 16:
+ conv >> std::hex >> result;
+ break;
+ }
+ my_ok = istringstream::eofbit & conv.rdstate();
+ if (!my_ok)
+ result = 0;
+ if (ok)
+ *ok = my_ok;
+ return result;
+}
+
void
Str::show() const
{
diff --git a/tests/libsample/str.h b/tests/libsample/str.h
index 52f46e6ba..1fe27ec8b 100644
--- a/tests/libsample/str.h
+++ b/tests/libsample/str.h
@@ -54,6 +54,8 @@ public:
char get_char(int pos) const;
bool set_char(int pos, char ch);
+ int toInt(bool* ok = 0, int base = 10) const;
+
void show() const;
int size() const { return m_str.size(); }