Add IsSpannedTextPlaced
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Text-ViewModel.cpp
index a3ad901..b13fcda 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
-#include <toolkit-text-utils.h>
+#include <dali-toolkit/devel-api/text/spannable-string.h>
+#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/font-description-run.h>
 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
 #include <dali-toolkit/internal/text/rendering/view-model.h>
-#include <dali-toolkit/internal/text/text-controller.h>
+#include <toolkit-text-utils.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -669,3 +670,89 @@ int UtcDaliTextViewModelElideText02(void)
   tet_result(TET_PASS);
   END_TEST;
 }
+
+int UtcDaliTextViewModelGetFontRuns(void)
+{
+  tet_infoline(" UtcDaliTextViewModelGetFontRuns");
+  ToolkitTestApplication application;
+
+  // Load some fonts.
+  TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+  fontClient.SetDpi(93u, 93u);
+
+  char*             pathNamePtr = get_current_dir_name();
+  const std::string pathName(pathNamePtr);
+  free(pathNamePtr);
+
+  fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
+
+  // Creates a text controller.
+  ControllerPtr controller = Controller::New();
+
+  // Tests the rendering controller has been created.
+  TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
+  DALI_TEST_CHECK(typesetter);
+
+  // Tests the view model has been created.
+  ViewModel* model = typesetter->GetViewModel();
+  DALI_TEST_CHECK(NULL != model);
+
+  // Configures the text controller similarly to the text-editor.
+  ConfigureTextEditor(controller);
+
+  // Sets a text and relais-out.
+  controller->SetMarkupProcessorEnabled(true);
+  controller->SetText("<font family='TizenSansRegular' size='10'>Hello </font>Hello<font family='TizenSansRegular' size='15'>Hello</font>");
+  controller->Relayout(CONTROL_SIZE);
+
+  const Vector<FontRun>& validFonts = model->GetFontRuns();
+
+  // The font-runs should be equal to number of segments have different fonts.
+  DALI_TEST_EQUALS(validFonts.Count(), 3u, TEST_LOCATION);
+
+  tet_result(TET_PASS);
+  END_TEST;
+}
+
+int UtcDaliTextViewModelGetFontDescriptionRuns(void)
+{
+  tet_infoline(" UtcDaliTextViewModelGetFontDescriptionRuns");
+  ToolkitTestApplication application;
+
+  // Load some fonts.
+  TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+  fontClient.SetDpi(93u, 93u);
+
+  char*             pathNamePtr = get_current_dir_name();
+  const std::string pathName(pathNamePtr);
+  free(pathNamePtr);
+
+  fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
+
+  // Creates a text controller.
+  ControllerPtr controller = Controller::New();
+
+  // Tests the rendering controller has been created.
+  TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
+  DALI_TEST_CHECK(typesetter);
+
+  // Tests the view model has been created.
+  ViewModel* model = typesetter->GetViewModel();
+  DALI_TEST_CHECK(NULL != model);
+
+  // Configures the text controller similarly to the text-editor.
+  ConfigureTextEditor(controller);
+
+  // Sets a text and relais-out.
+  controller->SetMarkupProcessorEnabled(true);
+  controller->SetText("<font family='TizenSansRegular' size='10'>Hello </font>Hello<font family='TizenSansRegular' size='15'>Hello</font>");
+  controller->Relayout(CONTROL_SIZE);
+
+  const Vector<FontDescriptionRun>& validFonts = model->GetFontDescriptionRuns();
+
+  // The font-description-runs should be equal number of the used fonts.
+  DALI_TEST_EQUALS(validFonts.Count(), 2u, TEST_LOCATION);
+
+  tet_result(TET_PASS);
+  END_TEST;
+}
\ No newline at end of file