7 #include "../../../../uidescription/uiviewfactory.h" 8 #include "../../../../uidescription/uiviewcreator.h" 9 #include "../../../../uidescription/uiattributes.h" 10 #include "../../../../lib/cbitmap.h" 11 #include "../../../../lib/cgradient.h" 12 #include "../../../../lib/cstring.h" 13 #include "../uidescriptionadapter.h" 17 constexpr IdStringPtr kColorName =
"MyColor";
18 constexpr IdStringPtr kFontName =
"MyFont";
19 constexpr IdStringPtr kBitmapName =
"MyBitmap";
20 constexpr IdStringPtr kGradientName =
"MyGradient";
21 constexpr IdStringPtr kTagName =
"tagname";
26 bool getColor (UTF8StringPtr name,
CColor& color)
const override 36 UTF8StringPtr lookupColorName (
const CColor& color)
const override 38 if (this->color == color)
43 CFontRef getFont (UTF8StringPtr name)
const override 50 UTF8StringPtr lookupFontName (
const CFontRef font)
const override 52 if (font == this->font)
57 CBitmap* getBitmap (UTF8StringPtr name)
const override 64 UTF8StringPtr lookupBitmapName (
const CBitmap* inBitmap)
const override 66 if (inBitmap == bitmap)
71 CGradient* getGradient (UTF8StringPtr name)
const override 78 UTF8StringPtr lookupGradientName (
const CGradient* gradient)
const override 80 if (gradient == this->gradient)
85 int32_t getTagForName (UTF8StringPtr name)
const override 91 UTF8StringPtr lookupControlTagName (
const int32_t
tag)
const override 93 if (this->tag != -1 &&
tag == this->tag)
105 CColor color {20, 30, 50, 255};
112 inline void testPossibleValues (
const IdStringPtr className,
const std::string& attrName,
IUIDescription* desc, UIViewFactory::StringList expectedValues)
116 a.setAttribute (UIViewCreator::kAttrClass, className);
117 auto view = owned (factory.createView (a, desc));
118 UIViewFactory::StringPtrList values;
119 EXPECT(factory.getPossibleAttributeListValues (view, attrName, values));
120 for (
auto& v : expectedValues)
122 EXPECT(std::find_if (values.begin(), values.end(), [&] (
const UIViewFactory::StringPtrList::value_type& value) {
124 }) != values.end ());
126 EXPECT(values.size () == expectedValues.size ());
129 inline void testMinMaxValues (
const IdStringPtr className,
const std::string& attrName, IUIDescription* desc,
double minValue,
double maxValue)
131 UIViewFactory factory;
133 a.setAttribute (UIViewCreator::kAttrClass, className);
134 auto view = owned (factory.createView (a, desc));
136 EXPECT (factory.getAttributeValueRange(view, attrName, min, max));
137 EXPECT(min == minValue);
138 EXPECT(max == maxValue);
141 template<
typename ViewClass,
typename Proc>
142 void testAttribute (
const IdStringPtr viewName,
const std::string& attrName,
const IdStringPtr attrValue, IUIDescription* desc,
const Proc& proc,
bool disableRememberAttributes =
false)
144 UIViewFactory factory;
145 factory.disableRememberAttributes = disableRememberAttributes;
147 a.setAttribute (UIViewCreator::kAttrClass, viewName);
148 a.setAttribute (attrName, attrValue);
150 auto v = owned (factory.createView (a, desc));
151 auto view = v.cast<ViewClass> ();
156 factory.getAttributesForView (view, desc, a2);
157 auto str = a2.getAttributeValue (attrName);
159 EXPECT(*str == attrValue);
162 template<
typename ViewClass,
typename Proc>
163 void testAttribute (
const IdStringPtr viewName,
const std::string& attrName, int32_t attrValue, IUIDescription* desc,
const Proc& proc)
165 UIViewFactory factory;
167 a.setAttribute (UIViewCreator::kAttrClass, viewName);
168 a.setIntegerAttribute (attrName, attrValue);
170 auto v = owned (factory.createView (a, desc));
171 auto view = v.cast<ViewClass> ();
176 factory.getAttributesForView (view, desc, a2);
178 a2.getIntegerAttribute (attrName, value);
179 EXPECT(value == attrValue);
182 template<
typename ViewClass,
typename Proc>
183 void testAttribute (
const IdStringPtr viewName,
const std::string& attrName,
bool attrValue, IUIDescription* desc,
const Proc& proc)
185 UIViewFactory factory;
187 a.setAttribute (UIViewCreator::kAttrClass, viewName);
188 a.setBooleanAttribute (attrName, attrValue);
190 auto v = owned (factory.createView (a, desc));
191 auto view = v.cast<ViewClass> ();
196 factory.getAttributesForView (view, desc, a2);
198 a2.getBooleanAttribute (attrName, value);
199 EXPECT(value == attrValue);
202 template<
typename ViewClass,
typename Proc>
203 void testAttribute (
const IdStringPtr viewName,
const std::string& attrName,
double attrValue, IUIDescription* desc,
const Proc& proc)
205 UIViewFactory factory;
207 a.setAttribute (UIViewCreator::kAttrClass, viewName);
208 a.setDoubleAttribute (attrName, attrValue);
210 auto v = owned (factory.createView (a, desc));
211 auto view = v.cast<ViewClass> ();
216 factory.getAttributesForView (view, desc, a2);
218 a2.getDoubleAttribute (attrName, value);
219 EXPECT(value == attrValue);
222 template<
typename ViewClass,
typename Proc>
223 void testAttribute (
const IdStringPtr viewName,
const std::string& attrName,
const CRect& attrValue, IUIDescription* desc,
const Proc& proc)
225 UIViewFactory factory;
227 a.setAttribute (UIViewCreator::kAttrClass, viewName);
228 a.setRectAttribute (attrName, attrValue);
230 auto v = owned (factory.createView (a, desc));
231 auto view = v.cast<ViewClass> ();
236 factory.getAttributesForView (view, desc, a2);
238 a2.getRectAttribute (attrName, value);
239 EXPECT(value == attrValue);
242 template<
typename ViewClass,
typename Proc>
243 void testAttribute (
const IdStringPtr viewName,
const std::string& attrName,
const CPoint& attrValue, IUIDescription* desc,
const Proc& proc)
245 UIViewFactory factory;
247 a.setAttribute (UIViewCreator::kAttrClass, viewName);
248 a.setPointAttribute (attrName, attrValue);
250 auto v = owned (factory.createView (a, desc));
251 auto view = v.cast<ViewClass> ();
256 factory.getAttributesForView (view, desc, a2);
258 a2.getPointAttribute (attrName, value);
259 EXPECT(value == attrValue);
262 inline bool operator!= (
const CGradient& g1,
const CGradient& g2)
264 auto cs1 = g1.getColorStops ();
265 auto cs2 = g2.getColorStops ();
269 inline bool operator== (
const CGradient& g1,
const CGradient& g2)
271 auto cs1 = g1.getColorStops ();
272 auto cs2 = g2.getColorStops ();
font class
Definition: cfont.h:31
Definition: iuidescription.h:19
Default view factory.
Definition: uiviewfactory.h:19
Definition: xmlparse.c:181
Definition: vstguibase.h:299
RGBA Color structure.
Definition: ccolor.h:15
Gradient Object [new in 4.0].
Definition: cgradient.h:19
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
Definition: uiattributes.h:21
Definition: uidescriptionadapter.h:11
a view on a null terminated UTF-8 String
Definition: cstring.h:172
Definition: icontrollistener.h:14