Bug 1314624 - Convert SampleWordBreakUsage() to a gtest. r=m_kato
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 12 Nov 2016 15:00:51 +0900
changeset 438321 dc661e1aa5ed02dcfbc644472f5377e6ce2c0faa
parent 438320 35e7f81763324e9e33d8002c3addaaf75fbb08ed
child 438322 162e1d1d9565e6d825c02b3e738bfaa1bf9766d6
push id35679
push userbmo:timdream@gmail.com
push dateMon, 14 Nov 2016 09:29:38 +0000
reviewersm_kato
bugs1314624
milestone52.0a1
Bug 1314624 - Convert SampleWordBreakUsage() to a gtest. r=m_kato MozReview-Commit-ID: HItg8STx7fD
intl/lwbrk/gtest/TestLineBreak.cpp
--- a/intl/lwbrk/gtest/TestLineBreak.cpp
+++ b/intl/lwbrk/gtest/TestLineBreak.cpp
@@ -186,17 +186,17 @@ static const char wb0[] = "T";
 static const char wb1[] = "h";
 static const char wb2[] = "is   is a int";
 static const char wb3[] = "ernationali";
 static const char wb4[] = "zation work.";
 
 static const char* wb[] = { wb0, wb1, wb2, wb3, wb4 };
 
 void
-SamplePrintWordWithBreak()
+TestPrintWordWithBreak()
 {
   uint32_t numOfFragment = sizeof(wb) / sizeof(char*);
   nsIWordBreaker* wbk = nullptr;
 
   CallGetService(kWBrkCID, &wbk);
 
   nsAutoString result;
 
@@ -224,24 +224,25 @@ SamplePrintWordWithBreak()
                                      nextFragText.get(),
                                      nextFragText.Length());
       if (canBreak) {
         result.Append('^');
       }
       fragText.Assign(nextFragText);
     }
   }
-  printf("Output From SamplePrintWordWithBreak() \n\n");
-  printf("[%s]\n", NS_ConvertUTF16toUTF8(result).get());
+  ASSERT_STREQ("is^   ^is^ ^a^ ^  is a intzation^ ^work^ation work.",
+               NS_ConvertUTF16toUTF8(result).get());
 
   NS_IF_RELEASE(wbk);
 }
 
 void
-SampleFindWordBreakFromPosition(uint32_t fragN, uint32_t offset)
+TestFindWordBreakFromPosition(uint32_t fragN, uint32_t offset,
+                              const char* expected)
 {
   uint32_t numOfFragment = sizeof(wb) / sizeof(char*);
   nsIWordBreaker* wbk = nullptr;
 
   CallGetService(kWBrkCID, &wbk);
 
   NS_ConvertASCIItoUTF16 fragText(wb[fragN]);
 
@@ -294,31 +295,29 @@ SampleFindWordBreakFromPosition(uint32_t
 
       if (0 != r.mBegin) {
         break;
       }
       prevFragText.Assign(curFragText);
     }
   }
 
-  printf("Output From SamplePrintWordWithBreak() \n\n");
-  printf("[%s]\n", NS_ConvertUTF16toUTF8(result).get());
+  ASSERT_STREQ(expected, NS_ConvertUTF16toUTF8(result).get())
+    << "FindWordBreakFromPosition(" << fragN << ", " << offset << ")";
 
   NS_IF_RELEASE(wbk);
 }
 
-// XXX: this prints output but doesn't actually test anything and so cannot
-// fail. Bug 1314497 is open to convert it to a real test.
-TEST(LineBreak, SampleWordBreakUsage)
+TEST(LineBreak, WordBreakUsage)
 {
-  SamplePrintWordWithBreak();
-  SampleFindWordBreakFromPosition(0,0);  // This
-  SampleFindWordBreakFromPosition(1,0);  // This
-  SampleFindWordBreakFromPosition(2,0);  // This
-  SampleFindWordBreakFromPosition(2,1);  // This
-  SampleFindWordBreakFromPosition(2,9);  // [space]
-  SampleFindWordBreakFromPosition(2,10); // internationalization
-  SampleFindWordBreakFromPosition(3,4);  // internationalization
-  SampleFindWordBreakFromPosition(3,8);  // internationalization
-  SampleFindWordBreakFromPosition(4,6);  // [space]
-  SampleFindWordBreakFromPosition(4,7);  // work
+  TestPrintWordWithBreak();
+  TestFindWordBreakFromPosition(0, 0, "This");
+  TestFindWordBreakFromPosition(1, 0, "his");
+  TestFindWordBreakFromPosition(2, 0, "is");
+  TestFindWordBreakFromPosition(2, 1, "is");
+  TestFindWordBreakFromPosition(2, 9, " ");
+  TestFindWordBreakFromPosition(2, 10, "internationalization");
+  TestFindWordBreakFromPosition(3, 4, "ernationalization");
+  TestFindWordBreakFromPosition(3, 8, "ernationalization");
+  TestFindWordBreakFromPosition(4, 6, " ");
+  TestFindWordBreakFromPosition(4, 7, "work");
 }