Author: rpmcruz
Date: Fri Aug 22 03:31:52 2008
New Revision: 50300
URL: http://svn.opensuse.org/viewcvs/yast?rev=50300&view=rev
Log:
* src/test.cc: truncate tests.
Modified:
trunk/gtk/ChangeLog
trunk/gtk/src/YGUtils.cc
trunk/gtk/src/YGUtils.h
trunk/gtk/src/test.cc
Modified: trunk/gtk/ChangeLog
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/ChangeLog?rev=50300&r1=50299&r2=50300&view=diff
==============================================================================
--- trunk/gtk/ChangeLog (original)
+++ trunk/gtk/ChangeLog Fri Aug 22 03:31:52 2008
@@ -3,6 +3,8 @@
* src/yzypptags.cc: bug request 418676: use title capitalization for
group names.
+ * src/test.cc: truncate tests.
+
2008-08-18 Ricardo Cruz
* src/ygtkcellrenderertextpixbuf.h/c: bug fix 416544: we must add the
Modified: trunk/gtk/src/YGUtils.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUtils.cc?rev=50300&r1=50299&r2=50300&view=diff
==============================================================================
--- trunk/gtk/src/YGUtils.cc (original)
+++ trunk/gtk/src/YGUtils.cc Fri Aug 22 03:31:52 2008
@@ -79,7 +79,7 @@
}
}
-std::string YGUtils::truncate (const std::string &str, unsigned int length, int pos)
+std::string YGUtils::truncate (const std::string &str, std::string::size_type length, int pos)
{
std::string ret (str);
if (ret.size() > length) {
@@ -92,7 +92,7 @@
ret.insert (0, "...");
}
else /* (pos == 0) */ {
- int delta = ret.size()-(length-3);
+ std::string::size_type delta = ret.size()-(length-3);
ret.erase ((ret.size()/2)-(delta/2), delta);
ret.insert (ret.size()/2, "...");
}
Modified: trunk/gtk/src/YGUtils.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUtils.h?rev=50300&r1=50299&r2=50300&view=diff
==============================================================================
--- trunk/gtk/src/YGUtils.h (original)
+++ trunk/gtk/src/YGUtils.h Fri Aug 22 03:31:52 2008
@@ -26,7 +26,7 @@
/* Truncates the text with "..." past the given length.
pos: -1 = start, 0 = middle, 1 = end */
- std::string truncate (const std::string &str, unsigned int length, int pos);
+ std::string truncate (const std::string &str, std::string::size_type length, int pos);
/* Escapes markup text (eg. changes '<' by '\<'). */
void escapeMarkup (std::string &str);
Modified: trunk/gtk/src/test.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/test.cc?rev=50300&r1=50299&r2=50300&view=diff
==============================================================================
--- trunk/gtk/src/test.cc (original)
+++ trunk/gtk/src/test.cc Fri Aug 22 03:31:52 2008
@@ -69,16 +69,13 @@
"<body><ul><li>foo</li><li>baa</li></ul></body>" },
{ "no outer<p>unclosed<p>several<b>unclosed bold",
"<body>no outer<p>unclosed</p><p>several<b>unclosed bold</b></p></body>" },
- // multiple white spacing -- proper HTML would had collapsed those multiple
- // spaces -- not important anyway
- { "one day I will do", "<body>one day I will do</body>" },
// comment
{ "we need <b>to <!-- really need to? --> do something</b> about it.",
- "<body>we need <b>to do something</b> about it.</body>" },
+ "<body>we need <b>to do something</b> about it.</body>" },
{ NULL, NULL }
};
for (int i = 0; aTests[i].in; i++) {
- gchar *out = ygutils_convert_to_xhmlt_and_subst (aTests[i].in);
+ gchar *out = ygutils_convert_to_xhtml (aTests[i].in);
if (strcmp (out, aTests[i].out)) {
fprintf (stderr, "Mis-converted entry %d XML '%s' should be '%s'\n",
i, out, aTests[i].out);
@@ -117,6 +114,38 @@
return true;
}
+bool testTruncate()
+{
+ fprintf (stderr, "Test truncate\t");
+ struct {
+ const char *in;
+ const char *out;
+ int length, pos;
+ } aTests[] = {
+ { "this-is-a-very-long-and-tedious-string", "this-is-a-very-lo...", 20, 1 },
+ { "this-is-a-very-long-and-tedious-string", "...nd-tedious-string", 20, -1 },
+ { "this-is-a-very-long-and-tedious-string", "this-is-...as-string", 20, 0 },
+ { "this-is-a-very-long-and-tedious-string2", "this-is-...s-string2", 20, 0 },
+ { "abc", "abc", 3, 1 },
+ { "abcd", "...", 3, 1 },
+ { "abcd", "...", 3, -1 },
+ { "abcd", "...", 3, 0 },
+ { "abcdef", "...a", 4, 0 },
+ { NULL, NULL }
+ };
+ for (int i = 0; aTests[i].in; i++) {
+ string out = YGUtils::truncate (aTests[i].in, aTests[i].length, aTests[i].pos);
+ if (out != aTests[i].out) {
+ fprintf (stderr, "Mis-converted entry %d truncate '%s' should be '%s'\n",
+ i, out.c_str(), aTests[i].out);
+ return false;
+ }
+ fprintf (stderr, "%d ", i);
+ }
+ fprintf (stderr, "\n");
+ return true;
+}
+
int main (int argc, char **argv)
{
bool bSuccess = true;
@@ -124,6 +153,7 @@
bSuccess &= testMapKBAccel();
bSuccess &= testXHtmlConvert();
bSuccess &= testMarkupEscape();
+ bSuccess &= testTruncate();
return !bSuccess;
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org