@@ -106,3 +106,83 @@ TEST_CASE("elementimage.dp_ratio")
106
106
document->Close ();
107
107
TestsShell::ShutdownShell ();
108
108
}
109
+
110
+
111
+
112
+ static const String document_wrapped_image_rml_ratio_test = R"(
113
+ <rml>
114
+ <head>
115
+ <title>Test</title>
116
+ <style>
117
+ .width-50 { width: 50px; }
118
+ .height-50 { height: 50px; }
119
+ .height-100 { height: 100px; }
120
+ </style>
121
+ </head>
122
+ <body>
123
+ <img src="/test_not_loaded/test_512_256.tga" id="test1" alt="Original size" />
124
+ <img src="/test_not_loaded/test_512_256.tga" id="test2" height="50" alt="Set height to 50, width auto, attribute set" />
125
+ <img src="/test_not_loaded/test_512_256.tga" id="test3" class="height-50" alt="Set height to 50, width auto, css set" />
126
+ <img src="/test_not_loaded/test_512_256.tga" id="test4" width="50" alt="Set width to 50, height auto, attribute set" />
127
+ <img src="/test_not_loaded/test_512_256.tga" id="test5" class="width-50" alt="Set width to 50, height auto, css set" />
128
+ <img src="/test_not_loaded/test_512_256.tga" id="test6" width="50" height="100" alt="Set width to 50 and height to 100, attribute set" />
129
+ <img src="/test_not_loaded/test_512_256.tga" id="test7" class="height-100 width-50" alt="Set width to 50 and height to 100, css set" />
130
+ </body>
131
+ </rml>
132
+ )" ;
133
+
134
+ TEST_CASE (" elementimage.preserve_ratio" )
135
+ {
136
+ Context* context = TestsShell::GetContext ();
137
+ ElementDocument* document = context->LoadDocumentFromMemory (document_wrapped_image_rml_ratio_test, " assets/" );
138
+ document->Show ();
139
+
140
+ // Texture size is hardcoded in test render interface to 512x256
141
+ SUBCASE (" baseline" )
142
+ {
143
+ Element* img_test1 = document->GetElementById (" test1" );
144
+ CHECK (img_test1->GetClientWidth () == 512 );
145
+ CHECK (img_test1->GetClientHeight () == 256 );
146
+ }
147
+ SUBCASE (" height only - attribute set" )
148
+ {
149
+ Element* img_test2 = document->GetElementById (" test2" );
150
+ CHECK (img_test2->GetClientWidth () == 100 );
151
+ CHECK (img_test2->GetClientHeight () == 50 );
152
+ }
153
+ SUBCASE (" height only - css set" )
154
+ {
155
+ Element* img_test3 = document->GetElementById (" test3" );
156
+ CHECK (img_test3->GetClientWidth () == 100 );
157
+ CHECK (img_test3->GetClientHeight () == 50 );
158
+ }
159
+ SUBCASE (" width only - attribute set" )
160
+ {
161
+ Element* img_test4 = document->GetElementById (" test4" );
162
+ CHECK (img_test4->GetClientWidth () == 50 );
163
+ CHECK (img_test4->GetClientHeight () == 25 );
164
+ }
165
+ SUBCASE (" width only - attribute set" )
166
+ {
167
+ Element* img_test5 = document->GetElementById (" test5" );
168
+ CHECK (img_test5->GetClientWidth () == 50 );
169
+ CHECK (img_test5->GetClientHeight () == 25 );
170
+ }
171
+ SUBCASE (" height and width - attribute set" )
172
+ {
173
+ Element* img_test6 = document->GetElementById (" test6" );
174
+ CHECK (img_test6->GetClientWidth () == 50 );
175
+ CHECK (img_test6->GetClientHeight () == 100 );
176
+ }
177
+ SUBCASE (" height and width - css set" )
178
+ {
179
+ Element* img_test7 = document->GetElementById (" test7" );
180
+ CHECK (img_test7->GetClientWidth () == 50 );
181
+ CHECK (img_test7->GetClientHeight () == 100 );
182
+ }
183
+
184
+ TestsShell::RenderLoop ();
185
+
186
+ document->Close ();
187
+ TestsShell::ShutdownShell ();
188
+ }
0 commit comments