/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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/internal/text/text-run-container.h>
#include <dali-toolkit-test-suite-utils.h>
#include <dali-toolkit/dali-toolkit.h>
-#include <toolkit-text-model.h>
+#include <toolkit-text-utils.h>
using namespace Dali;
using namespace Toolkit;
unsigned int numberOfCharacters; ///< The number of characters.
unsigned int numberOfLineInfo; ///< The number or reordered lines.
BidiLineData* bidiLineData; ///< The bidirectional line info.
+ unsigned int numberOfLines; ///< The number of laid-out lines.
+ bool* lineDirections; ///< The directions of the lines.
};
struct GetMirroredTextData
struct GetCharactersDirectionData
{
- std::string description; ///< Description of the test.
- std::string text; ///< Input text.
- unsigned int startIndex; ///< The index from where the model is updated.
- unsigned int numberOfCharacters; ///< The number of characters.
- bool* directions; ///< The expected directions.
+ std::string description; ///< Description of the test.
+ std::string text; ///< Input text.
+ unsigned int startIndex; ///< The index from where the model is updated.
+ unsigned int numberOfCharacters; ///< The number of characters.
+ bool* directions; ///< The expected directions.
+ bool markupProcessorEnabled; ///< Enable markup processor to use markup text.
};
bool SetBidirectionalInfoTest( const SetBidirectionalInfoData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
// Create the model.
+ const Vector<FontDescriptionRun> fontDescriptions;
+ const LayoutOptions options;
CreateTextModel( data.text,
textArea,
+ fontDescriptions,
+ options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics,
+ false );
// 2) Clear the bidirectional paragraph info data.
Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo;
bool ReorderLinesTest( const ReorderLinesData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 300.f);
Size layoutSize;
// Create the model.
+ const Vector<FontDescriptionRun> fontDescriptions;
+ const LayoutOptions options;
CreateTextModel( data.text,
textArea,
+ fontDescriptions,
+ options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics,
+ false );
// 2) Clear the bidirectional line info data.
uint32_t startRemoveIndex = logicalModel->mBidirectionalLineInfo.Count();
}
}
+ if( data.numberOfLines != visualModel->mLines.Count() )
+ {
+ std::cout << "Different number of lines : " << visualModel->mLines.Count() << ", expected : " << data.numberOfLines << std::endl;
+
+ unsigned int index = 0u;
+ for( Vector<LineRun>::ConstIterator it = visualModel->mLines.Begin(),
+ endIt = visualModel->mLines.End();
+ it != endIt;
+ ++it, ++index )
+ {
+ const LineRun& line = *it;
+
+ if( line.direction != *( data.lineDirections + index ) )
+ {
+ std::cout << " Different line direction : " << line.direction << ", expected : " << *( data.lineDirections + index ) << std::endl;
+ return false;
+ }
+ }
+ }
+
return true;
}
bool GetMirroredTextTest( const GetMirroredTextData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
// Create the model.
+ const Vector<FontDescriptionRun> fontDescriptions;
+ const LayoutOptions options;
CreateTextModel( data.text,
textArea,
+ fontDescriptions,
+ options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics,
+ false );
// 2) Call the GetMirroredText() function for the whole text
Vector<Character> mirroredText;
bool GetCharactersDirectionTest( const GetCharactersDirectionData& data )
{
// 1) Create the model.
- LogicalModelPtr logicalModel = LogicalModel::New();
- VisualModelPtr visualModel = VisualModel::New();
+ LogicalModelPtr logicalModel;
+ VisualModelPtr visualModel;
+ MetricsPtr metrics;
Size textArea(100.f, 60.f);
Size layoutSize;
// Create the model.
+ const Vector<FontDescriptionRun> fontDescriptions;
+ const LayoutOptions options;
CreateTextModel( data.text,
textArea,
+ fontDescriptions,
+ options,
layoutSize,
logicalModel,
- visualModel );
+ visualModel,
+ metrics,
+ data.markupProcessorEnabled );
Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo;
// 2) Clear the direction info data.
Vector<CharacterDirection>& directions = logicalModel->mCharacterDirections;
- directions.Erase( directions.Begin() + data.startIndex,
- directions.Begin() + data.startIndex + data.numberOfCharacters );
+ if( directions.Count() >= data.startIndex + data.numberOfCharacters )
+ {
+ directions.Erase( directions.Begin() + data.startIndex,
+ directions.Begin() + data.startIndex + data.numberOfCharacters );
+ }
// 3) Call GetCharactersDirection() function.
int UtcDaliSetBidirectionalInfo(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliSetBidirectionalInfo");
unsigned int indices01[] = {};
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !SetBidirectionalInfoTest( data[index] ) )
{
tet_result(TET_FAIL);
int UtcDaliReorderLines(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliSetBidirectionalInfo");
unsigned int visualToLogical0301[] = { 0u, 1u, 2u, 3u, 4u, 5u, 9u, 8u, 7u, 6u, 10u };
},
};
+ bool directions02[] = { false, false, false, false, false, false };
+ bool directions03[] = { false, false, false, false, false, true, true, true, true, true, false, false, false, false, false, true, true, true, true, true };
+
struct ReorderLinesData data[] =
{
{
0u,
0u,
0u,
- bidiLine01
+ bidiLine01,
+ 0u,
+ NULL
},
{
"Left to right text only.",
0u,
51u,
0u,
- bidiLine02
+ bidiLine02,
+ 6u,
+ directions02
},
{
"Bidirectional paragraphs.",
0u,
195u,
16u,
- bidiLine03
+ bidiLine03,
+ 20u,
+ directions03
},
{
"Bidirectional paragraphs. Update initial paragraphs.",
0u,
44u,
16u,
- bidiLine03
+ bidiLine03,
+ 20u,
+ directions03
},
{
"Bidirectional paragraphs. Update middle paragraphs.",
44u,
54u,
16u,
- bidiLine03
+ bidiLine03,
+ 20u,
+ directions03
},
{
"Bidirectional paragraphs. Update final paragraphs.",
142u,
53u,
16u,
- bidiLine03
+ bidiLine03,
+ 20u,
+ directions03
},
};
const unsigned int numberOfTests = 6u;
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !ReorderLinesTest( data[index] ) )
{
tet_result(TET_FAIL);
int UtcDaliGetMirroredText(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliGetMirroredText");
struct GetMirroredTextData data[] =
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !GetMirroredTextTest( data[index] ) )
{
tet_result(TET_FAIL);
int UtcDaliGetCharactersDirection(void)
{
- ToolkitTestApplication application;
tet_infoline(" UtcDaliGetCharactersDirection");
bool directions01[] = {};
true, true, true, true, true, true, true, true, true, true,
true, true, false, false, false, false, false };
+ bool directions06[] = {
+ true, true, true, true, true, true, true, true, true, true,
+ false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false };
+
struct GetCharactersDirectionData data[] =
{
{
"",
0u,
0u,
- directions01
+ directions01,
+ false
},
{
"Left to right characters only",
"Hello world\nhello world demo",
0u,
28u,
- directions02
+ directions02,
+ false
},
{
"Right to left characters only",
"שלום עולם\nשלום עולם",
0u,
19u,
- directions03
+ directions03,
+ false
},
{
"Mix of bidirectional text",
"Hello world\nhello world שלום עולם\nשלום עולם hello world",
0u,
55u,
- directions04
+ directions04,
+ false
},
{
"Mix of bidirectional text. With more paragraphs.",
" مرحبا بالعالم שלום עולם hello world hello world\nبالعالم שלום hello world demo עולם\nשלום مرحبا بالعالم עולם hello",
0u,
227u,
- directions05
+ directions05,
+ false
},
{
"Mix of bidirectional text. With more paragraphs. Update first paragraph.",
" مرحبا بالعالم שלום עולם hello world hello world\nبالعالم שלום hello world demo עולם\nשלום مرحبا بالعالم עולם hello",
0u,
17u,
- directions05
+ directions05,
+ false
},
{
"Mix of bidirectional text. With more paragraphs. Update from character 29",
" مرحبا بالعالم שלום עולם hello world hello world\nبالعالم שלום hello world demo עולם\nשלום مرحبا بالعالم עולם hello",
29u,
134u,
- directions05
+ directions05,
+ false
},
{
"Mix of bidirectional text. With more paragraphs. Update from character 163",
" مرحبا بالعالم שלום עולם hello world hello world\nبالعالم שלום hello world demo עולם\nשלום مرحبا بالعالم עולם hello",
163u,
35u,
- directions05
+ directions05,
+ false
+ },
+ {
+ "Mix of bidirectional text. With brackets and LRM",
+ "שלום עולם ‎(hello)[world]‎",
+ 0u,
+ 26u,
+ directions06,
+ true
}
};
- const unsigned int numberOfTests = 8u;
+ const unsigned int numberOfTests = 9u;
for( unsigned int index = 0u; index < numberOfTests; ++index )
{
+ ToolkitTestApplication application;
if( !GetCharactersDirectionTest( data[index] ) )
{
tet_result(TET_FAIL);