Initial release

This commit is contained in:
civ
2026-08-16 18:24:52 +07:00
commit 876886a39a
13244 changed files with 2353959 additions and 0 deletions
@@ -0,0 +1,75 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../uidescription/base64codec.h"
#include "../unittests.h"
#include <string>
namespace VSTGUI {
TEST_CASE (Base64CodecTest, EncodeAscii)
{
std::string test ("ABCD");
auto result = Base64Codec::encode (test.data (), test.size ());
EXPECT (result.dataSize == 8);
uint8_t* ptr = result.data.get ();
EXPECT (ptr[0] == 'Q');
EXPECT (ptr[1] == 'U');
EXPECT (ptr[2] == 'J');
EXPECT (ptr[3] == 'D');
EXPECT (ptr[4] == 'R');
EXPECT (ptr[5] == 'A');
EXPECT (ptr[6] == '=');
EXPECT (ptr[7] == '=');
}
TEST_CASE (Base64CodecTest, EncodeBinary)
{
uint8_t binary[6];
binary[0] = 0x89;
binary[1] = 0x50;
binary[2] = 0x4E;
binary[3] = 0x47;
binary[4] = 0x0D;
binary[5] = 0x0A;
auto result = Base64Codec::encode (binary, 6);
EXPECT (result.dataSize == 8);
uint8_t* ptr = result.data.get ();
EXPECT (ptr[0] == 'i');
EXPECT (ptr[1] == 'V');
EXPECT (ptr[2] == 'B');
EXPECT (ptr[3] == 'O');
EXPECT (ptr[4] == 'R');
EXPECT (ptr[5] == 'w');
EXPECT (ptr[6] == '0');
EXPECT (ptr[7] == 'K');
}
TEST_CASE (Base64CodecTest, DecodeAscii)
{
std::string test ("QUJDRA");
auto result = Base64Codec::decode (test);
EXPECT (result.dataSize == 4);
uint8_t* ptr = result.data.get ();
EXPECT (ptr[0] == 'A');
EXPECT (ptr[1] == 'B');
EXPECT (ptr[2] == 'C');
EXPECT (ptr[3] == 'D');
}
TEST_CASE (Base64CodecTest, DecodeBinary)
{
std::string test ("iVBORw0K");
auto result = Base64Codec::decode (test);
EXPECT (result.dataSize == 6);
uint8_t* ptr = result.data.get ();
EXPECT (ptr[0] == 0x89);
EXPECT (ptr[1] == 0x50);
EXPECT (ptr[2] == 0x4E);
EXPECT (ptr[3] == 0x47);
EXPECT (ptr[4] == 0x0D);
EXPECT (ptr[5] == 0x0A);
}
}
@@ -0,0 +1,140 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../uidescription/cstream.h"
#include "../unittests.h"
namespace VSTGUI {
TEST_CASE (CMemoryStreamTest, ReadWrite)
{
CMemoryStream s;
uint64_t value = 1;
uint32_t size = sizeof (value);
EXPECT (s.writeRaw (&value, size) == size);
EXPECT (s.tell () == size);
s.rewind ();
value = 20;
EXPECT (s.readRaw (&value, size) == size);
EXPECT (value == 1);
}
TEST_CASE (CMemoryStreamTest, Overread)
{
CMemoryStream s;
uint32_t value = 1;
EXPECT (s.writeRaw (&value, sizeof (value)) == sizeof (value));
s.rewind ();
uint64_t value2;
EXPECT (s.readRaw (&value2, sizeof (value2)) < sizeof (value2));
}
TEST_CASE (CMemoryStreamTest, Seek)
{
constexpr uint32_t bufferSize = 32;
int8_t buffer[bufferSize];
CMemoryStream s (buffer, bufferSize);
EXPECT (s.seek (33, CMemoryStream::kSeekEnd) == kStreamSeekError);
EXPECT (s.seek (0, CMemoryStream::kSeekEnd) == 32);
EXPECT (s.seek (-2, CMemoryStream::kSeekCurrent) == 30);
EXPECT (s.seek (15, CMemoryStream::kSeekSet) == 15);
}
TEST_CASE (CMemoryStreamTest, ReadWriteValueLittleEndian)
{
CMemoryStream s;
OutputStream& os = s;
os.setByteOrder (kLittleEndianByteOrder);
os << static_cast<int8_t> (1);
os << static_cast<uint8_t> (2);
os << static_cast<int16_t> (3);
os << static_cast<uint16_t> (4);
os << static_cast<int32_t> (5);
os << static_cast<uint32_t> (6);
os << static_cast<int64_t> (7);
os << static_cast<uint64_t> (8);
os << static_cast<double> (9);
s.rewind ();
InputStream& is = s;
is.setByteOrder (kLittleEndianByteOrder);
int8_t v1;
EXPECT (is >> v1);
EXPECT (v1 == 1);
uint8_t v2;
EXPECT (is >> v2);
EXPECT (v2 == 2);
int16_t v3;
EXPECT (is >> v3);
EXPECT (v3 == 3);
uint16_t v4;
EXPECT (is >> v4);
EXPECT (v4 == 4);
int32_t v5;
EXPECT (is >> v5);
EXPECT (v5 == 5);
uint32_t v6;
EXPECT (is >> v6);
EXPECT (v6 == 6);
int64_t v7;
EXPECT (is >> v7);
EXPECT (v7 == 7);
uint64_t v8;
EXPECT (is >> v8);
EXPECT (v8 == 8);
double v9;
EXPECT (is >> v9);
EXPECT (v9 == 9.0);
}
TEST_CASE (CMemoryStreamTest, ReadWriteValueBigEndian)
{
CMemoryStream s;
OutputStream& os = s;
os.setByteOrder (kBigEndianByteOrder);
os << static_cast<int8_t> (1);
os << static_cast<uint8_t> (2);
os << static_cast<int16_t> (3);
os << static_cast<uint16_t> (4);
os << static_cast<int32_t> (5);
os << static_cast<uint32_t> (6);
os << static_cast<int64_t> (7);
os << static_cast<uint64_t> (8);
os << static_cast<double> (9);
os << std::string ("Test");
s.rewind ();
InputStream& is = s;
is.setByteOrder (kBigEndianByteOrder);
int8_t v1;
EXPECT (is >> v1);
EXPECT (v1 == 1);
uint8_t v2;
EXPECT (is >> v2);
EXPECT (v2 == 2);
int16_t v3;
EXPECT (is >> v3);
EXPECT (v3 == 3);
uint16_t v4;
EXPECT (is >> v4);
EXPECT (v4 == 4);
int32_t v5;
EXPECT (is >> v5);
EXPECT (v5 == 5);
uint32_t v6;
EXPECT (is >> v6);
EXPECT (v6 == 6);
int64_t v7;
EXPECT (is >> v7);
EXPECT (v7 == 7);
uint64_t v8;
EXPECT (is >> v8);
EXPECT (v8 == 8);
double v9;
EXPECT (is >> v9);
EXPECT (v9 == 9.0);
std::string str;
EXPECT (is >> str);
EXPECT (str == "Test");
}
} // VSTGUI
@@ -0,0 +1,159 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../uidescription/delegationcontroller.h"
#include "../../../uidescription/uiattributes.h"
#include "../unittests.h"
namespace VSTGUI {
namespace {
class Controller : public IController
{
public:
mutable bool funcCalled {false};
void valueChanged (CControl* pControl) override { funcCalled = true; }
int32_t controlModifierClicked (CControl* pControl, CButtonState button) override
{
funcCalled = true;
return 0;
}
void controlBeginEdit (CControl* pControl) override { funcCalled = true; }
void controlEndEdit (CControl* pControl) override { funcCalled = true; }
void controlTagWillChange (CControl* pControl) override { funcCalled = true; }
void controlTagDidChange (CControl* pControl) override { funcCalled = true; }
int32_t getTagForName (UTF8StringPtr name, int32_t registeredTag) const override
{
funcCalled = true;
return registeredTag;
}
IControlListener* getControlListener (UTF8StringPtr controlTagName) override
{
funcCalled = true;
return this;
}
CView* createView (const UIAttributes& attributes, const IUIDescription* description) override
{
funcCalled = true;
return nullptr;
}
CView* verifyView (CView* view, const UIAttributes& attributes,
const IUIDescription* description) override
{
funcCalled = true;
return view;
}
IController* createSubController (UTF8StringPtr name,
const IUIDescription* description) override
{
funcCalled = true;
return nullptr;
}
};
} // anonymous
TEST_CASE (DelegationControllerTest, ValueChanged)
{
Controller myController;
DelegationController dc (&myController);
dc.valueChanged (nullptr);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, ControlModifierClicked)
{
Controller myController;
DelegationController dc (&myController);
dc.controlModifierClicked (nullptr, kLButton);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, ControlBeginEdit)
{
Controller myController;
DelegationController dc (&myController);
dc.controlBeginEdit (nullptr);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, ControlEndEdit)
{
Controller myController;
DelegationController dc (&myController);
dc.controlEndEdit (nullptr);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, ControlTagWillChange)
{
Controller myController;
DelegationController dc (&myController);
dc.controlTagWillChange (nullptr);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, ControlTagDidChange)
{
Controller myController;
DelegationController dc (&myController);
dc.controlTagDidChange (nullptr);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, GetTagForName)
{
Controller myController;
DelegationController dc (&myController);
dc.getTagForName ("", 0);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, GetControlListener)
{
Controller myController;
DelegationController dc (&myController);
dc.getControlListener ("");
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, CreateView)
{
Controller myController;
DelegationController dc (&myController);
UIAttributes a;
dc.createView (a, nullptr);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, VerifyView)
{
Controller myController;
DelegationController dc (&myController);
UIAttributes a;
dc.verifyView (nullptr, a, nullptr);
EXPECT (myController.funcCalled);
}
TEST_CASE (DelegationControllerTest, CreateSubController)
{
Controller myController;
DelegationController dc (&myController);
dc.createSubController ("", nullptr);
EXPECT (myController.funcCalled);
}
} // VSTGUI
@@ -0,0 +1,218 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../lib/cpoint.h"
#include "../../../lib/crect.h"
#include "../../../uidescription/cstream.h"
#include "../../../uidescription/uiattributes.h"
#include "../unittests.h"
namespace VSTGUI {
static UTF8StringPtr attributes[] = {"K1", "V1", "K2", "V2", nullptr};
TEST_CASE (UIAttributesTest, ArrayConstructor)
{
UIAttributes a (attributes);
EXPECT (a.hasAttribute ("K1"));
EXPECT (a.hasAttribute ("K2"));
EXPECT (*a.getAttributeValue ("K1") == "V1");
EXPECT (*a.getAttributeValue ("K2") == "V2");
}
TEST_CASE (UIAttributesTest, SetGetStringValue)
{
UIAttributes a;
a.setAttribute ("Key", "Value");
EXPECT (a.hasAttribute ("Key"));
EXPECT (*a.getAttributeValue ("Key") == "Value");
}
TEST_CASE (UIAttributesTest, RemoveAttribute)
{
UIAttributes a;
a.setAttribute ("Key", "Value");
a.removeAttribute ("Key");
EXPECT (a.hasAttribute ("Key") == false);
}
TEST_CASE (UIAttributesTest, BoolAttribute)
{
UIAttributes a;
bool value = false;
EXPECT (a.getBooleanAttribute ("Key", value) == false);
a.setBooleanAttribute ("Key", true);
EXPECT (a.getBooleanAttribute ("Key", value));
EXPECT (value == true);
a.setBooleanAttribute ("Key", false);
EXPECT (a.getBooleanAttribute ("Key", value));
EXPECT (value == false);
}
TEST_CASE (UIAttributesTest, IntegerAttribute)
{
UIAttributes a;
int32_t value = 0;
EXPECT (a.getIntegerAttribute ("Key", value) == false);
a.setIntegerAttribute ("Key", 10);
EXPECT (a.getIntegerAttribute ("Key", value));
EXPECT (value == 10);
}
TEST_CASE (UIAttributesTest, DoubleAttribute)
{
UIAttributes a;
double value = 0.;
EXPECT (a.getDoubleAttribute ("Key", value) == false);
a.setDoubleAttribute ("Key", 3.45);
EXPECT (a.getDoubleAttribute ("Key", value));
EXPECT (value == 3.45);
}
TEST_CASE (UIAttributesTest, PointAttribute)
{
UIAttributes a;
CPoint value;
EXPECT (a.getPointAttribute ("Key", value) == false);
a.setPointAttribute ("Key", CPoint (5, 5));
EXPECT (a.getPointAttribute ("Key", value));
EXPECT (value == CPoint (5, 5));
}
TEST_CASE (UIAttributesTest, RectAttribute)
{
UIAttributes a;
CRect value;
EXPECT (a.getRectAttribute ("Key", value) == false);
a.setRectAttribute ("Key", CRect (10, 20, 30, 40));
EXPECT (a.getRectAttribute ("Key", value));
EXPECT (value == CRect (10, 20, 30, 40));
}
TEST_CASE (UIAttributesTest, StringArrayAttribute)
{
UIAttributes a;
UIAttributes::StringArray array;
array.push_back ("1");
array.push_back ("2");
array.push_back ("3");
UIAttributes::StringArray array2;
EXPECT (a.getStringArrayAttribute ("Key", array2) == false);
a.setStringArrayAttribute ("Key", array);
EXPECT (a.getStringArrayAttribute ("Key", array2));
EXPECT (array == array2);
}
TEST_CASE (UIAttributesTest, RemoveAll)
{
UIAttributes a;
a.setRectAttribute ("Key1", CRect (10, 20, 30, 40));
a.setDoubleAttribute ("Key2", 3.45);
a.removeAll ();
EXPECT (a.begin () == a.end ());
}
TEST_CASE (UIAttributesTest, StoreRestore)
{
UIAttributes a;
CMemoryStream s2;
EXPECT (a.restore (s2) == false);
a.setAttribute ("Key1", "Value");
a.setBooleanAttribute ("Key2", true);
a.setIntegerAttribute ("Key3", 10);
a.setDoubleAttribute ("Key4", 3.45);
a.setPointAttribute ("Key5", CPoint (5, 5));
a.setRectAttribute ("Key6", CRect (10, 20, 30, 40));
a.setDoubleAttribute ("Key7", 3.45);
CMemoryStream s;
a.store (s);
s.rewind ();
UIAttributes a2;
a2.restore (s);
for (auto& v : a)
{
auto value = a2.getAttributeValue (v.first);
EXPECT (value);
EXPECT_EQ (*value, v.second);
}
}
TEST_CASE (UIAttributesTest, RestoreFromInvalidStream)
{
CMemoryStream s;
UIAttributes a;
EXPECT (a.restore (s) == false);
s.rewind ();
uint32_t someValue = 0;
s.writeRaw (&someValue, sizeof (someValue));
s.rewind ();
EXPECT (a.restore (s) == false);
}
TEST_CASE (UIAttributesTest, StringToBool)
{
bool b;
EXPECT (UIAttributes::stringToBool ("hola", b) == false)
EXPECT (UIAttributes::stringToBool ("true 5", b) == false)
EXPECT (UIAttributes::stringToBool ("true", b) && b == true)
EXPECT (UIAttributes::stringToBool ("false", b) && b == false)
}
TEST_CASE (UIAttributesTest, StringToInteger)
{
int32_t i;
EXPECT (UIAttributes::stringToInteger ("s5s5", i) == false)
EXPECT (UIAttributes::stringToInteger ("5s5", i) == false)
EXPECT (UIAttributes::stringToInteger ("1.0", i) == false)
EXPECT (UIAttributes::stringToInteger ("hola", i) == false)
EXPECT (UIAttributes::stringToInteger ("151515", i) && i == 151515)
}
TEST_CASE (UIAttributesTest, StringToDouble)
{
double d;
EXPECT (UIAttributes::stringToDouble ("as5.5", d) == false)
EXPECT (UIAttributes::stringToDouble ("5.5sa", d) == false)
EXPECT (UIAttributes::stringToDouble ("5.567.5", d) == false)
EXPECT (UIAttributes::stringToDouble ("hola", d) == false)
EXPECT (UIAttributes::stringToDouble ("25.5", d) && d == 25.5)
EXPECT (UIAttributes::stringToDouble (".5", d) && d == 0.5)
EXPECT (UIAttributes::stringToDouble (" -0.5", d) && d == -0.5)
}
TEST_CASE (UIAttributesTest, StringToPoint)
{
CPoint p;
EXPECT (UIAttributes::stringToPoint ("30, 20, 50", p) == false)
EXPECT (UIAttributes::stringToPoint ("30, 20a", p) == false)
EXPECT (UIAttributes::stringToPoint ("a, b", p) == false)
EXPECT (UIAttributes::stringToPoint ("20", p) == false)
EXPECT (UIAttributes::stringToPoint ("15, 25", p) && p == CPoint (15, 25))
EXPECT (UIAttributes::stringToPoint ("1.768, 25", p) && p == CPoint (1.768, 25))
}
TEST_CASE (UIAttributesTest, StringToRect)
{
CRect r;
EXPECT (UIAttributes::stringToRect ("30, 20, 50", r) == false)
EXPECT (UIAttributes::stringToRect ("30, 20, 50, 60, 80", r) == false)
EXPECT (UIAttributes::stringToRect ("30, 20, 50, 60a", r) == false)
EXPECT (UIAttributes::stringToRect ("a, b, c, d", r) == false)
EXPECT (UIAttributes::stringToRect ("0, 12.5, 5, 8", r) && r == CRect (0, 12.5, 5, 8))
}
TEST_CASE (UIAttributesTest, StringArrayToStringWithEmptyStringArray)
{
const UIAttributes::StringArray strings;
const auto s = UIAttributes::stringArrayToString (strings);
EXPECT (s.empty ())
}
} // VSTGUI
@@ -0,0 +1,99 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../uidescription/uidescriptionaddonregistry.h"
#include "../../../uidescription/uidescription.h"
#include "../../../uidescription/uicontentprovider.h"
#include "../../../lib/cview.h"
#include "../unittests.h"
//------------------------------------------------------------------------
namespace VSTGUI {
namespace {
//------------------------------------------------------------------------
constexpr auto createViewUIDesc = R"(
{
"vstgui-ui-description": {
"version": "1",
"templates": {
"view": {
"attributes": {
"background-color": "~ TransparentCColor",
"background-color-draw-style": "filled and stroked",
"class": "CViewContainer",
"mouse-enabled": "true",
"opacity": "1",
"origin": "0, 0",
"size": "400, 235",
"transparent": "false"
},
"children": {
"CView": {
"attributes": {
"class": "CView",
"mouse-enabled": "true",
"opacity": "1",
"origin": "4, 10",
"size": "392, 40",
"transparent": "false"
}
}
}
}
}
}
}
)";
} // anonymous
//------------------------------------------------------------------------
TEST_CASE (UIDescriptionAddOnTest, BasicFunctionality)
{
struct BaseAddOn : UIDescriptionAddOnAdapter
{
void afterParsing (IUIDescription* desc) override { afterParsingCalled = true; }
void beforeSaving (IUIDescription* desc) override { beforeSavingCalled = true; }
void onDestroy (IUIDescription* desc) override { onDestroyCalled = true; }
CreateTemplateViewFunc onCreateTemplateView (const IUIDescription* desc,
const CreateTemplateViewFunc& f) override
{
onCreateTemplateViewCalled = true;
return f;
}
IViewFactory* getViewFactory (IUIDescription* desc, IViewFactory* of) override
{
getViewFactoryCalled = true;
return of;
};
bool afterParsingCalled {false};
bool beforeSavingCalled {false};
bool onDestroyCalled {false};
bool onCreateTemplateViewCalled {false};
bool getViewFactoryCalled {false};
};
auto myAddOn = std::make_unique<BaseAddOn> ();
auto myAddOnPtr = myAddOn.get ();
auto token = UIDescriptionAddOnRegistry::add (std::move (myAddOn));
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT_TRUE (myAddOnPtr->getViewFactoryCalled);
EXPECT_TRUE (desc.parse ());
EXPECT_TRUE (myAddOnPtr->afterParsingCalled);
auto view = desc.createView ("view", nullptr);
EXPECT_NE (view, nullptr);
EXPECT_TRUE (myAddOnPtr->onCreateTemplateViewCalled);
view->forget ();
}
EXPECT_TRUE (myAddOnPtr->onDestroyCalled);
UIDescriptionAddOnRegistry::remove (token);
}
//------------------------------------------------------------------------
} // VSTGUI
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,118 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#pragma once
#include "../../../uidescription/icontroller.h"
#include "../../../uidescription/uidescription.h"
#include "../../../uidescription/uidescriptionlistener.h"
#include "../unittests.h"
namespace VSTGUI {
namespace UIDescriptionTesting {
struct SaveUIDescription : public UIDescription
{
SaveUIDescription (IContentProvider* xmlContentProvider) : UIDescription (xmlContentProvider) {}
using UIDescription::saveToStream;
};
struct Controller : public IController
{
void valueChanged (CControl* pControl) override {};
int32_t getTagForName (UTF8StringPtr name, int32_t registeredTag) const override
{
return registeredTag;
}
IControlListener* getControlListener (UTF8StringPtr controlTagName) override { return this; }
CView* createView (const UIAttributes& attributes, const IUIDescription* description) override
{
return nullptr;
}
CView* verifyView (CView* view, const UIAttributes& attributes,
const IUIDescription* description) override
{
return view;
}
IController* createSubController (UTF8StringPtr name,
const IUIDescription* description) override
{
return nullptr;
}
};
enum class UIDescTestCase
{
TagChanged,
ColorChanged,
FontChanged,
BitmapChanged,
TemplateChanged,
GradientChanged,
BeforeSave
};
//-----------------------------------------------------------------------------
class DescriptionListenerMock : public UIDescriptionListenerAdapter
{
public:
DescriptionListenerMock (UIDescTestCase tc) { setTestCase (tc); }
void setTestCase (UIDescTestCase tc)
{
testCase = tc;
called = 0u;
}
uint32_t callCount () const { return called; }
bool doUIDescTemplateUpdate (UIDescription* desc, UTF8StringPtr name) override
{
EXPECT (false);
return true;
}
void onUIDescTagChanged (UIDescription* desc) override
{
++called;
EXPECT (testCase == UIDescTestCase::TagChanged)
}
void onUIDescColorChanged (UIDescription* desc) override
{
++called;
EXPECT (testCase == UIDescTestCase::ColorChanged)
}
void onUIDescFontChanged (UIDescription* desc) override
{
++called;
EXPECT (testCase == UIDescTestCase::FontChanged)
}
void onUIDescBitmapChanged (UIDescription* desc) override
{
++called;
EXPECT (testCase == UIDescTestCase::BitmapChanged)
}
void onUIDescTemplateChanged (UIDescription* desc) override
{
++called;
EXPECT (testCase == UIDescTestCase::TemplateChanged)
}
void onUIDescGradientChanged (UIDescription* desc) override
{
++called;
EXPECT (testCase == UIDescTestCase::GradientChanged)
}
void beforeUIDescSave (UIDescription* desc) override
{
++called;
EXPECT (testCase == UIDescTestCase::BeforeSave)
}
private:
UIDescTestCase testCase;
uint32_t called;
};
} // UIDescriptionTesting
} // VSTGUI
@@ -0,0 +1,902 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../lib/cbitmap.h"
#include "../../../lib/ccolor.h"
#include "../../../lib/cgradient.h"
#include "../../../lib/cviewcontainer.h"
#include "../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../uidescription/uiattributes.h"
#include "../../../uidescription/uicontentprovider.h"
#include "../../../uidescription/xmlparser.h"
#include "uidescription_test_helper.h"
#if VSTGUI_ENABLE_XML_PARSER
namespace VSTGUI {
using namespace UIDescriptionTesting;
namespace {
static constexpr auto defaultSafeFlags =
UIDescription::kWriteImagesIntoUIDescFile | UIDescription::kWriteAsXML;
constexpr auto emptyUIDesc = R"(
<vstgui-ui-description version="1">
</vstgui-ui-description>
)";
constexpr auto colorNodesUIDesc = R"(
<vstgui-ui-description version="1">
<colors>
<color name="c1" rgba="#000000ff"/>
<color name="c2" rgb="#ffffff"/>
<color name="c3" red="255" green="0" blue="0" alpha="100"/>
<color name="c4" red="0" green="255" blue="0" alpha="150"/>
<color name="c5" red="255" green="0" blue="255" alpha="100"/>
</colors>
</vstgui-ui-description>
)";
constexpr auto fontNodesUIDesc = R"(
<vstgui-ui-description version="1">
<fonts>
<font font-name="Arial" name="f1" size="8"/>
<font font-name="Arial" name="f2" size="8" bold="true"/>
<font font-name="Arial" name="f3" size="8" italic="true"/>
<font font-name="Arial" name="f4" size="8" underline="true"/>
<font font-name="Arial" name="f5" size="8" strike-through="true"/>
<font font-name="bla" name="f6" size="8" alternative-font-names="Arial, Courier"/>
</fonts>
</vstgui-ui-description>
)";
constexpr auto bitmapNodesUIDesc = R"(
<vstgui-ui-description version="1">
<bitmaps>
<bitmap name="b1" path="b1.png"/>
<bitmap name="b1#2.0x" path="b1#2.0x.png" scale-factor="2"/>
</bitmaps>
</vstgui-ui-description>
)";
constexpr auto tagNodesUIDesc = R"(
<vstgui-ui-description version="1">
<control-tags>
<control-tag name="t1" tag="1234"/>
<control-tag name="t2" tag="4321"/>
<control-tag name="t3" tag="'mytg'"/>
</control-tags>
</vstgui-ui-description>
)";
constexpr auto calculateTagNodesUIDesc = R"(
<vstgui-ui-description version="1">
<control-tags>
<control-tag name="t1" tag="1+2"/>
</control-tags>
</vstgui-ui-description>
)";
constexpr auto gradientNodesUIDesc = R"(
<vstgui-ui-description version="1">
<gradients>
<gradient name="g1">
<color-stop rgba="#000000ff" start="0"/>
<color-stop rgba="#ff0000ff" start="0.5"/>
<color-stop rgba="#ffffffff" start="1"/>
</gradient>
</gradients>
</vstgui-ui-description>
)";
constexpr auto variableNodesUIDesc = R"(
<vstgui-ui-description version="1">
<variables>
<var name="v1" type="number" value="10"/>
<var name="v2" type="string" value="string"/>
<var name="v3" value="string"/>
<var name="v4" value="20.5"/>
<var name="v5" type="string" value="2*var.v1"/>
<var name="v6"/>
</variables>
</vstgui-ui-description>
)";
constexpr auto withAllNodesUIDesc = R"(<?xml version="1.0" encoding="UTF-8"?>
<vstgui-ui-description version="1">
<colors>
<color name="c1" rgba="#000000ff"/>
<color name="c2" rgb="#ffffff"/>
<color alpha="100" blue="0" green="0" name="c3" red="255"/>
</colors>
<fonts>
<font font-name="Arial" name="f1" size="8"/>
<font bold="true" font-name="Arial" name="f2" size="8"/>
</fonts>
<!-- a comment -->
<bitmaps>
<bitmap name="b1" path="b1.png">
<data encoding="base64">
iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAABe2lDQ1BJQ0MgUHJvZmlsZQAAKJF9kE0rRF
EYx38zXjNkwcLC4jaG1RCjvGyUmYSaxTRGedvcueZFmXG7c4VsLJTtFCU23hZ8AjYWylopRUrKVyA20vUc
Q+OlPHXO+Z3nPM+/5/zB7ddNc7a0HTJZ24oOBrWx8Qmt4gEX5XjQ8OpGzuyPRMJIfJ0/4+VaqiWuWpXW3/
d/wzOdyBngqhTuM0zLFh4SblqwTcVKr96SoYRXFKcKvKE4XuCjj5pYNCR8KqwZaX1a+E7Yb6StDLiVvi/+
rSb1jTOz88bnPOon1Yns6IicXlmN5IgySFC8GGaAEF100Ct7F60EaJMbdmLRVs2hOXPJmkmlba1fnEhow1
mjza8F2ju6Qfn6269ibm4Xep6hJF/MxTfhZA0abos53w7UrsLxualb+keqRJY7mYTHQ6gZh7pLqJrMJTsD
hR9VB6Hs3nGemqFiHd7yjvO65zhv+9IsHp1lCx59anFwA7FlCF/A1ja0iHbt1Dv7WWccXX/QZQAAAExJRE
FUKBVjZEAALSAzDMFFYa0C8q6BRJhQhBEcUSAThIkGDUCVIIwBcNmAoRAmMKoBFhL4aEagJLYYhkXaazTN
q1jQBGBcdIUwcQYAOGIGVqwWW9EAAAAASUVORK5CYII=
</data>
</bitmap>
<bitmap name="b1#2.0x" path="b1#2.0x.png" scale-factor="2"/>
<bitmap name="dataBitmap" path="dataBitmap.png"/>
</bitmaps>
<control-tags>
<control-tag name="t1" tag="1234"/>
<control-tag name="t2" tag="4321"/>
</control-tags>
<gradients>
<gradient name="g1">
<color-stop rgba="#000000ff" start="0"/>
<color-stop rgba="#ff0000ff" start="0.5"/>
<color-stop rgba="#ffffffff" start="1"/>
</gradient>
</gradients>
<variables>
<var name="test" type="number" value="10"/>
<var name="test" type="string" value="this is a string"/>
</variables>
</vstgui-ui-description>
)";
constexpr auto createViewUIDesc = R"(
<vstgui-ui-description version="1">
<template background-color="~ TransparentCColor" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="view" opacity="1" origin="0, 0" size="400, 235" transparent="false">
<view class="CView" mouse-enabled="true" opacity="1" origin="4, 10" size="392, 40" transparent="false"/>
</template>
</vstgui-ui-description>
)";
constexpr auto restoreViewUIDesc = R"(
<vstgui-ui-description version="1">
<template background-color="~ TransparentCColor" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="view" opacity="1" origin="0, 0" size="400, 235" transparent="false">
<view class="CViewContainer" mouse-enabled="true" opacity="1" origin="4, 10" size="392, 40" transparent="false"/>
<view class="CViewContainer" mouse-enabled="true" opacity="1" origin="4, 10" size="392, 40" transparent="false">
<view class="CView" mouse-enabled="true" opacity="1" origin="4, 10" size="392, 40" transparent="false"/>
</view>
</template>
</vstgui-ui-description>
)";
constexpr auto completeExample = R"(
<vstgui-ui-description version="1">
<colors>
</colors>
<custom>
<attributes name="UIViewInspector" windowSize="71, 194, 471, 709"/>
<attributes name="UIViewHierarchyBrowser" windowSize="513, 194, 813, 694"/>
<attributes name="FocusDrawing"/>
<attributes name="UIGridController"/>
<attributes SelectedTemplate="tab1" name="UITemplateController"/>
<attributes EditViewScale="1" EditorSize="0, 0, 1244, 755" SplitViewSize_0_0="0.8228882833787466433150825650955084711313" SplitViewSize_0_1="0.1498637602179836436633308949240017682314" SplitViewSize_1_0="0.480926430517711167578198683258960954845" SplitViewSize_1_1="0.5122615803814714041664046817459166049957" SplitViewSize_2_0="0.7033762057877813722583937305898871272802" SplitViewSize_2_1="0.2926045016077170601853651987767079845071" Version="1" name="UIEditController"/>
<attributes name="UIAttributesController"/>
<attributes SelectedRow="20" name="UIViewCreatorDataSource"/>
</custom>
<bitmaps>
<bitmap name="animation_knob" path="animation_knob.png"/>
<bitmap name="FrameBackground" nineparttiled-offsets="10, 20, 10, 10" path="FrameBackground.png"/>
<bitmap name="TabController" path="TabController.png"/>
<bitmap name="horizontal_slider_back" path="horizontal_slider_back.bmp"/>
<bitmap name="onoff_button" path="onoff_button.bmp"/>
<bitmap name="rocker_switch" path="rocker_switch.bmp"/>
<bitmap name="slider_handle" path="slider_handle.bmp"/>
<bitmap name="switch_horizontal" path="switch_horizontal.bmp"/>
<bitmap name="switch_vertical" path="switch_vertical.bmp"/>
<bitmap name="vertical_slider_back" path="vertical_slider_back.bmp"/>
<bitmap name="vumeter_back" path="vumeter_back.bmp"/>
<bitmap name="vumeter_front" path="vumeter_front.bmp"/>
</bitmaps>
<fonts>
</fonts>
<control-tags>
<control-tag name="Switch" tag="20000"/>
</control-tags>
<variables/>
<template autosize="left right top bottom " background-color="~ WhiteCColor" background-color-draw-style="filled and stroked" class="CViewContainer" maxSize="300, 500" minSize="150, 300" mouse-enabled="true" name="view" opacity="1" origin="0, 0" size="300, 500" transparent="false">
<view animation-style="fade" animation-time="120" background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="UIViewSwitchContainer" mouse-enabled="true" opacity="1" origin="10, 10" size="280, 480" transparent="false"/>
</template>
<template autosize="left right top bottom " background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="tab1" opacity="1" origin="0, 0" size="280, 480" transparent="true">
<view background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CLayeredViewContainer" mouse-enabled="true" opacity="1" origin="10, 20" size="100, 100" transparent="false" z-index="0"/>
<view background-color="~ BlackCColor" background-color-draw-style="filled and stroked" bitmap="0" class="CShadowViewContainer" mouse-enabled="true" opacity="1" origin="130, 20" shadow-blur-size="4" shadow-intensity="0.3" shadow-offset="0, 0" size="200, 200" transparent="false"/>
<view auto-drag-scrolling="false" auto-hide-scrollbars="false" background-color="~ BlackCColor" background-color-draw-style="filled and stroked" bordered="true" class="CScrollView" container-size="200, 200" follow-focus-view="false" horizontal-scrollbar="true" mouse-enabled="true" opacity="1" origin="40, 240" overlay-scrollbars="false" scrollbar-background-color="#ffffffc8" scrollbar-frame-color="~ BlackCColor" scrollbar-scroller-color="~ BlueCColor" scrollbar-width="16" size="100, 100" transparent="false" vertical-scrollbar="true"/>
<view animate-view-resizing="false" background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CRowColumnView" equal-size-layout="left-top" margin="0,0,0,0" mouse-enabled="true" opacity="1" origin="60, 360" row-style="true" size="100, 100" spacing="0" transparent="false" view-resize-animation-time="200"/>
<view background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CSplitView" mouse-enabled="true" opacity="1" orientation="horizontal" origin="160, 280" resize-method="last" separator-width="10" size="100, 100" transparent="false"/>
</template>
<template autosize="left right top bottom row " background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="tab2" opacity="1" origin="0, 0" size="280, 480" transparent="true">
<view angle-range="270" angle-start="135" background-offset="0, 0" circle-drawing="false" class="CAnimKnob" corona-color="~ WhiteCColor" corona-dash-dot="false" corona-drawing="false" corona-from-center="false" corona-inset="0" corona-inverted="false" corona-outline="false" default-value="0.5" handle-color="~ WhiteCColor" handle-line-width="1" handle-shadow-color="~ GreyCColor" height-of-one-image="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 10" size="20, 20" sub-pixmaps="0" transparent="false" value-inset="0" wheel-inc-value="0.1" zoom-factor="1.5"/>
<view animation-index="0" animation-time="500" background-offset="0, 0" class="CAnimationSplashScreen" default-value="0.5" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="50, 10" size="20, 20" splash-origin="0, 0" splash-size="0, 0" transparent="false" wheel-inc-value="0.1"/>
<view autosize-to-fit="false" background-offset="0, 0" boxfill-color="~ WhiteCColor" boxframe-color="~ BlackCColor" checkmark-color="~ RedCColor" class="CCheckBox" default-value="0.5" draw-crossbox="false" font="~ SystemFont" font-color="~ WhiteCColor" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="110, 10" size="100, 20" title="Title" transparent="false" wheel-inc-value="0.1"/>
<view background-offset="0, 0" class="CControl" default-value="0.5" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="20, 50" size="20, 20" transparent="false" wheel-inc-value="0.1"/>
<view class="CGradientView" draw-antialiased="true" frame-color="~ BlackCColor" frame-width="1" gradient-angle="0" gradient-style="linear" mouse-enabled="true" opacity="1" origin="70, 50" radial-center="0.5, 0.5" radial-radius="1" round-rect-radius="5" size="100, 100" transparent="false"/>
<view background-offset="0, 0" class="CHorizontalSwitch" default-value="0" height-of-one-image="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="20, 160" size="20, 20" sub-pixmaps="0" transparent="false" wheel-inc-value="0.1"/>
<view background-offset="0, 0" class="CKickButton" default-value="0.5" height-of-one-image="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="70, 150" size="20, 20" sub-pixmaps="0" transparent="false" wheel-inc-value="0.1"/>
<view angle-range="270" angle-start="135" background-offset="0, 0" circle-drawing="false" class="CKnob" corona-color="~ WhiteCColor" corona-dash-dot="false" corona-drawing="false" corona-from-center="false" corona-inset="0" corona-inverted="false" corona-outline="false" default-value="0.5" handle-color="~ WhiteCColor" handle-line-width="1" handle-shadow-color="~ GreyCColor" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="120, 150" size="20, 20" transparent="false" value-inset="3" wheel-inc-value="0.1" zoom-factor="1.5"/>
<view background-offset="0, 0" class="CMovieBitmap" default-value="0.5" height-of-one-image="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="170, 160" size="20, 20" sub-pixmaps="0" transparent="false" wheel-inc-value="0.1"/>
<view background-offset="0, 0" class="CMovieButton" default-value="0.5" height-of-one-image="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="30, 200" size="20, 20" sub-pixmaps="0" transparent="false" wheel-inc-value="0.1"/>
<view background-offset="0, 0" class="COnOffButton" default-value="0.5" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="80, 190" size="20, 20" transparent="false" wheel-inc-value="0.1"/>
<view back-color="~ BlackCColor" background-offset="0, 0" class="COptionMenu" default-value="0.5" font="~ NormalFont" font-antialias="true" font-color="~ WhiteCColor" frame-color="~ BlackCColor" frame-width="1" max-value="1.84467e+19" menu-check-style="false" menu-popup-style="false" min-value="0" mouse-enabled="true" opacity="1" origin="140, 190" round-rect-radius="6" shadow-color="~ RedCColor" size="20, 20" style-3D-in="false" style-3D-out="false" style-no-draw="false" style-no-frame="false" style-no-text="false" style-round-rect="false" style-shadow-text="false" text-alignment="center" text-inset="0, 0" text-rotation="0" transparent="false" value-precision="2" wheel-inc-value="0.1"/>
<view back-color="~ BlackCColor" background-offset="0, 0" class="CParamDisplay" default-value="0.5" font="~ NormalFont" font-antialias="true" font-color="~ WhiteCColor" frame-color="~ BlackCColor" frame-width="1" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="30, 230" round-rect-radius="6" shadow-color="~ RedCColor" size="20, 20" style-3D-in="false" style-3D-out="false" style-no-draw="false" style-no-frame="false" style-no-text="false" style-round-rect="false" style-shadow-text="false" text-alignment="center" text-inset="0, 0" text-rotation="0" transparent="false" value-precision="2" wheel-inc-value="0.1"/>
<view background-offset="0, 0" class="CRockerSwitch" default-value="0.5" height-of-one-image="0" max-value="1" min-value="-1" mouse-enabled="true" opacity="1" origin="70, 230" size="20, 20" sub-pixmaps="3" transparent="false" wheel-inc-value="0.1"/>
<view background-offset="0, 0" class="CSegmentButton" default-value="0.5" font="~ NormalFont" frame-color="~ BlackCColor" frame-width="1" icon-text-margin="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="120, 230" round-radius="5" segment-names="Segment 1,Segment 2,Segment 3,Segment 4" size="200, 20" style="horizontal" text-alignment="center" text-color="~ BlackCColor" text-color-highlighted="~ WhiteCColor" transparent="false" wheel-inc-value="0.1"/>
<view background-offset="0, 0" bitmap-offset="0, 0" class="CSlider" default-value="0.5" draw-back="false" draw-back-color="~ WhiteCColor" draw-frame="false" draw-frame-color="~ WhiteCColor" draw-value="false" draw-value-color="~ WhiteCColor" draw-value-from-center="false" draw-value-inverted="false" handle-offset="0, 0" max-value="1" min-value="0" mode="free click" mouse-enabled="true" opacity="1" orientation="horizontal" origin="20, 270" reverse-orientation="false" size="20, 20" transparent="false" transparent-handle="true" wheel-inc-value="0.1" zoom-factor="10"/>
<view background-offset="0, 0" class="CTextButton" default-value="0.5" font="~ SystemFont" frame-color="~ BlackCColor" frame-color-highlighted="~ BlackCColor" frame-width="1" gradient="Default TextButton Gradient" gradient-highlighted="Default TextButton Gradient Highlighted" icon-position="left" icon-text-margin="0" kick-style="true" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="60, 270" round-radius="6" size="100, 20" text-alignment="center" text-color="~ BlackCColor" text-color-highlighted="~ WhiteCColor" transparent="false" wheel-inc-value="0.1"/>
<view back-color="~ BlackCColor" background-offset="0, 0" class="CTextEdit" default-value="0.5" font="~ NormalFont" font-antialias="true" font-color="~ WhiteCColor" frame-color="~ BlackCColor" frame-width="1" immediate-text-change="false" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="180, 270" round-rect-radius="6" shadow-color="~ RedCColor" size="100, 20" style-3D-in="false" style-3D-out="false" style-doubleclick="false" style-no-draw="false" style-no-frame="false" style-no-text="false" style-round-rect="false" style-shadow-text="false" text-alignment="center" text-inset="0, 0" text-rotation="0" transparent="false" value-precision="2" wheel-inc-value="0.1"/>
<view back-color="~ BlackCColor" background-offset="0, 0" class="CTextLabel" default-value="0.5" font="~ NormalFont" font-antialias="true" font-color="~ WhiteCColor" frame-color="~ BlackCColor" frame-width="1" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="20, 300" round-rect-radius="6" shadow-color="~ RedCColor" size="100, 20" style-3D-in="false" style-3D-out="false" style-no-draw="false" style-no-frame="false" style-no-text="false" style-round-rect="false" style-shadow-text="false" text-alignment="center" text-inset="0, 0" text-rotation="0" transparent="false" value-precision="2" wheel-inc-value="0.1"/>
<view background-offset="0, 0" class="CVerticalSwitch" default-value="0" height-of-one-image="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="20, 330" size="20, 20" sub-pixmaps="0" transparent="false" wheel-inc-value="0.1"/>
<view class="CView" mouse-enabled="true" opacity="1" origin="50, 330" size="20, 20" transparent="false"/>
<view background-offset="0, 0" class="CVuMeter" decrease-step-value="0.1" default-value="0.5" max-value="1" min-value="0" mouse-enabled="true" num-led="100" opacity="1" orientation="vertical" origin="90, 330" size="20, 20" transparent="false" wheel-inc-value="0.1"/>
<view back-color="~ BlackCColor" background-offset="0, 0" class="CXYPad" default-value="0.5" font="~ NormalFont" font-antialias="true" font-color="~ WhiteCColor" frame-color="~ BlackCColor" frame-width="1" max-value="2" min-value="0" mouse-enabled="true" opacity="1" origin="140, 330" round-rect-radius="6" shadow-color="~ RedCColor" size="100, 20" style-3D-in="false" style-3D-out="false" style-no-draw="false" style-no-frame="false" style-no-text="false" style-round-rect="false" style-shadow-text="false" text-alignment="center" text-inset="0, 0" text-rotation="0" transparent="false" value-precision="2" wheel-inc-value="0.1"/>
</template>
<gradients>
<gradient name="Default TextButton Gradient">
<color-stop rgba="#dcdcdcff" start="0"/>
<color-stop rgba="#b4b4b4ff" start="1"/>
</gradient>
<gradient name="Default TextButton Gradient Highlighted">
<color-stop rgba="#b4b4b4ff" start="0"/>
<color-stop rgba="#646464ff" start="1"/>
</gradient>
</gradients>
</vstgui-ui-description>
)";
constexpr auto sharedResourcesUIDesc = R"(<?xml version="1.0" encoding="UTF-8"?>
<vstgui-ui-description version="1">
<colors>
<color name="c1" rgba="#000000ff"/>
</colors>
<fonts>
<font font-name="Arial" name="f1" size="8"/>
</fonts>
<bitmaps>
<bitmap name="b1" path="b1.png">
<data encoding="base64">
iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAABe2lDQ1BJQ0MgUHJvZmlsZQAAKJF9kE0rRF
EYx38zXjNkwcLC4jaG1RCjvGyUmYSaxTRGedvcueZFmXG7c4VsLJTtFCU23hZ8AjYWylopRUrKVyA20vUc
Q+OlPHXO+Z3nPM+/5/zB7ddNc7a0HTJZ24oOBrWx8Qmt4gEX5XjQ8OpGzuyPRMJIfJ0/4+VaqiWuWpXW3/
d/wzOdyBngqhTuM0zLFh4SblqwTcVKr96SoYRXFKcKvKE4XuCjj5pYNCR8KqwZaX1a+E7Yb6StDLiVvi/+
rSb1jTOz88bnPOon1Yns6IicXlmN5IgySFC8GGaAEF100Ct7F60EaJMbdmLRVs2hOXPJmkmlba1fnEhow1
mjza8F2ju6Qfn6269ibm4Xep6hJF/MxTfhZA0abos53w7UrsLxualb+keqRJY7mYTHQ6gZh7pLqJrMJTsD
hR9VB6Hs3nGemqFiHd7yjvO65zhv+9IsHp1lCx59anFwA7FlCF/A1ja0iHbt1Dv7WWccXX/QZQAAAExJRE
FUKBVjZEAALSAzDMFFYa0C8q6BRJhQhBEcUSAThIkGDUCVIIwBcNmAoRAmMKoBFhL4aEagJLYYhkXaazTN
q1jQBGBcdIUwcQYAOGIGVqwWW9EAAAAASUVORK5CYII=
</data>
</bitmap>
</bitmaps>
<gradients>
<gradient name="g1">
<color-stop rgba="#000000ff" start="0"/>
<color-stop rgba="#ff0000ff" start="0.5"/>
<color-stop rgba="#ffffffff" start="1"/>
</gradient>
</gradients>
</vstgui-ui-description>
)";
} // anonymous
using StringPtrList = std::list<const std::string*>;
TEST_CASE (UIDescriptionXMLTests, ParseEmpty)
{
MemoryContentProvider provider (emptyUIDesc, static_cast<uint32_t> (strlen (emptyUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
EXPECT (desc.getGradient ("t") == nullptr);
EXPECT (desc.getBitmap ("b") == nullptr);
EXPECT (desc.getFont ("f") == nullptr);
EXPECT (desc.getTagForName ("t") == -1);
CColor c;
EXPECT (desc.getColor ("c", c) == false);
EXPECT (desc.getControlListener ("t") == nullptr);
EXPECT (desc.getController () == nullptr);
}
TEST_CASE (UIDescriptionXMLTests, Colors)
{
MemoryContentProvider provider (colorNodesUIDesc,
static_cast<uint32_t> (strlen (colorNodesUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
CColor c;
EXPECT (desc.getColor ("c1", c));
EXPECT (c == CColor (0, 0, 0, 255));
EXPECT (desc.getColor ("c2", c));
EXPECT (c == CColor (255, 255, 255, 255));
EXPECT (desc.getColor ("c3", c));
EXPECT (c == CColor (255, 0, 0, 100));
EXPECT (desc.getColor ("c4", c));
EXPECT (c == CColor (0, 255, 0, 150));
EXPECT (desc.getColor ("c5", c));
EXPECT (c == CColor (255, 0, 255, 100));
StringPtrList names;
desc.collectColorNames (names);
uint32_t numNames = 0;
for (auto& name : names)
{
if (name->at (0) != '~')
numNames++;
}
EXPECT (numNames == 5);
desc.changeColor ("c5", CColor (0, 255, 0, 255));
EXPECT (desc.getColor ("c5", c));
EXPECT (c == CColor (0, 255, 0, 255));
desc.changeColor ("added color node", CColor (1, 2, 3, 4));
EXPECT (desc.hasColorName ("added color node"));
auto name = desc.lookupColorName (CColor (0, 255, 0, 255));
EXPECT (name == std::string ("c5"));
desc.changeColorName ("c5", "new color");
EXPECT (desc.hasColorName ("new color"));
desc.removeColor ("new color");
EXPECT (desc.getColor ("new color", c) == false);
}
TEST_CASE (UIDescriptionXMLTests, Fonts)
{
MemoryContentProvider provider (fontNodesUIDesc,
static_cast<uint32_t> (strlen (fontNodesUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
EXPECT (desc.hasFontName ("f1"));
auto font = desc.getFont ("f1");
EXPECT (font->getName () == std::string ("Arial"));
EXPECT (font->getSize () == 8);
EXPECT (font->getStyle () == kNormalFace);
font = desc.getFont ("f2");
EXPECT (font->getName () == std::string ("Arial"));
EXPECT (font->getSize () == 8);
EXPECT (font->getStyle () == kBoldFace);
font = desc.getFont ("f3");
EXPECT (font->getName () == std::string ("Arial"));
EXPECT (font->getSize () == 8);
EXPECT (font->getStyle () == kItalicFace);
font = desc.getFont ("f4");
EXPECT (font->getName () == std::string ("Arial"));
EXPECT (font->getSize () == 8);
EXPECT (font->getStyle () == kUnderlineFace);
font = desc.getFont ("f5");
EXPECT (font->getName () == std::string ("Arial"));
EXPECT (font->getSize () == 8);
EXPECT (font->getStyle () == kStrikethroughFace);
font = desc.getFont ("f6");
EXPECT (font->getName () == std::string ("Arial"));
EXPECT (font->getSize () == 8);
std::string altFontNames;
EXPECT (desc.getAlternativeFontNames ("f5", altFontNames) == false);
EXPECT (desc.getAlternativeFontNames ("f6", altFontNames));
EXPECT (altFontNames == "Arial, Courier");
desc.changeAlternativeFontNames ("f6", "Courier");
desc.getAlternativeFontNames ("f6", altFontNames);
EXPECT (altFontNames == "Courier");
auto name = desc.lookupFontName (font);
EXPECT (name == std::string ("f6"));
StringPtrList names;
desc.collectFontNames (names);
uint32_t numNames = 0;
for (auto& n : names)
{
if (n->at (0) != '~')
numNames++;
}
EXPECT (numNames == 6);
desc.changeFontName ("f1", "font");
EXPECT (desc.hasFontName ("font"));
auto newFont = owned (new CFontDesc (*font));
desc.changeFont ("font", newFont);
desc.changeFont ("font2", newFont);
EXPECT (desc.getFont ("font") == newFont);
EXPECT (desc.getFont ("font2") == newFont);
desc.removeFont ("font");
EXPECT (desc.hasFontName ("font") == false);
}
TEST_CASE (UIDescriptionXMLTests, Bitmaps)
{
MemoryContentProvider provider (bitmapNodesUIDesc,
static_cast<uint32_t> (strlen (bitmapNodesUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
EXPECT (desc.hasBitmapName ("b1"));
auto bitmap = desc.getBitmap ("b1");
EXPECT (bitmap);
auto name = desc.lookupBitmapName (bitmap);
EXPECT (name == std::string ("b1"));
StringPtrList names;
desc.collectBitmapNames (names);
EXPECT (names.size () == 2);
desc.changeBitmapName ("b1", "new bitmap");
EXPECT (desc.hasBitmapName ("new bitmap"));
desc.removeBitmap ("new bitmap");
EXPECT (desc.hasBitmapName ("new bitmap") == false);
CRect ninePartTiledOffset (10, 10, 10, 10);
desc.changeBitmap ("added bitmap node", "path to bitmap", &ninePartTiledOffset);
EXPECT (desc.hasBitmapName ("added bitmap node"));
bitmap = desc.getBitmap ("added bitmap node");
EXPECT (dynamic_cast<CNinePartTiledBitmap*> (bitmap));
auto& offsets = dynamic_cast<CNinePartTiledBitmap*> (bitmap)->getPartOffsets ();
EXPECT (offsets.left == 10 && offsets.top == 10 && offsets.right == 10 && offsets.bottom == 10);
desc.changeBitmap ("added bitmap node", "added bitmap node", nullptr);
bitmap = desc.getBitmap ("added bitmap node");
EXPECT (dynamic_cast<CNinePartTiledBitmap*> (bitmap) == nullptr);
}
TEST_CASE (UIDescriptionXMLTests, Tags)
{
MemoryContentProvider provider (tagNodesUIDesc,
static_cast<uint32_t> (strlen (tagNodesUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
EXPECT (desc.hasTagName ("t1"));
EXPECT (desc.getTagForName ("t1") == 1234);
EXPECT (desc.getTagForName ("t3") == 1836676199);
auto name = desc.lookupControlTagName (1234);
EXPECT (name == std::string ("t1"));
StringPtrList names;
desc.collectControlTagNames (names);
EXPECT (names.size () == 3);
desc.changeTagName ("t1", "control tag");
EXPECT (desc.hasTagName ("control tag"));
desc.changeControlTagString ("control tag", "4567 - 5");
EXPECT (desc.getTagForName ("control tag") == 4562);
std::string tagString;
EXPECT (desc.getControlTagString ("control not existing", tagString) == false);
EXPECT (desc.getControlTagString ("control tag", tagString));
EXPECT (tagString == "4567 - 5");
desc.removeTag ("control tag");
EXPECT (desc.hasTagName ("control tag") == false);
desc.changeControlTagString ("new control tag", "2*2", true);
EXPECT (desc.getTagForName ("new control tag") == 4);
}
TEST_CASE (UIDescriptionXMLTests, LookupTagsCalculateTag)
{
MemoryContentProvider provider (calculateTagNodesUIDesc,
static_cast<uint32_t> (strlen (calculateTagNodesUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
auto name = desc.lookupControlTagName (3);
EXPECT (name);
EXPECT (std::string (name) == "t1");
}
TEST_CASE (UIDescriptionXMLTests, Gradient)
{
MemoryContentProvider provider (gradientNodesUIDesc,
static_cast<uint32_t> (strlen (gradientNodesUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
EXPECT (desc.hasGradientName ("g1"));
auto gradient = desc.getGradient ("g1");
const auto& colorStops = gradient->getColorStops ();
EXPECT (colorStops.size () == 3);
auto it = colorStops.find (0.);
EXPECT (it != colorStops.end ());
EXPECT (it->second == CColor (0, 0, 0, 255));
it = colorStops.find (0.5);
EXPECT (it != colorStops.end ());
EXPECT (it->second == CColor (255, 0, 0, 255));
it = colorStops.find (1.);
EXPECT (it != colorStops.end ());
EXPECT (it->second == CColor (255, 255, 255, 255));
auto name = desc.lookupGradientName (gradient);
EXPECT (name == std::string ("g1"));
StringPtrList names;
desc.collectGradientNames (names);
EXPECT (names.size () == 1);
desc.changeGradientName ("g1", "gradient");
EXPECT (desc.hasGradientName ("gradient"));
EXPECT (desc.hasGradientName ("g1") == false);
auto newGradient = owned (CGradient::create (0., 1., kWhiteCColor, kBlackCColor));
desc.changeGradient ("gradient", newGradient);
EXPECT (desc.getGradient ("gradient") == newGradient);
desc.changeGradient ("gradientnew", newGradient);
EXPECT (desc.hasGradientName ("gradientnew"));
desc.removeGradient ("gradientnew");
EXPECT (desc.hasGradientName ("gradientnew") == false);
}
TEST_CASE (UIDescriptionXMLTests, Variables)
{
MemoryContentProvider provider (variableNodesUIDesc,
static_cast<uint32_t> (strlen (variableNodesUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
double value;
EXPECT (desc.getVariable ("v1", value));
EXPECT (value == 10.);
std::string strValue;
EXPECT (desc.getVariable ("v2", strValue));
EXPECT (strValue == "string");
EXPECT (desc.getVariable ("v3", strValue));
EXPECT (strValue == "string");
EXPECT (desc.getVariable ("v4", value));
EXPECT (value == 20.5);
EXPECT (desc.getVariable ("v5", value));
EXPECT (value == 20.);
EXPECT (desc.getVariable ("v6", strValue));
EXPECT (strValue == "");
}
TEST_CASE (UIDescriptionXMLTests, Calculations)
{
MemoryContentProvider provider (tagNodesUIDesc,
static_cast<uint32_t> (strlen (tagNodesUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
double value;
EXPECT (desc.calculateStringValue ("1", value));
EXPECT (value == 1.);
EXPECT (desc.calculateStringValue ("1+1", value));
EXPECT (value == 2.);
EXPECT (desc.calculateStringValue ("(1+1)*2", value));
EXPECT (value == 4.);
EXPECT (desc.calculateStringValue ("(1+1)*2-(3/3 + (0.5+0.5))", value));
EXPECT (value == 2.);
EXPECT (desc.calculateStringValue ("tag.t1 - 4", value));
EXPECT (value == 1230.);
EXPECT (desc.calculateStringValue ("(1+5*3", value) == false);
EXPECT (desc.calculateStringValue ("tag.unknown - 4", value) == false);
EXPECT (desc.calculateStringValue ("var.unknown", value) == false);
EXPECT (desc.calculateStringValue ("unknown", value) == false);
}
TEST_CASE (UIDescriptionXMLTests, WriteToStream)
{
std::string str (withAllNodesUIDesc);
MemoryContentProvider provider (str.data (), static_cast<uint32_t> (str.size ()));
SaveUIDescription desc (&provider);
EXPECT (desc.parse () == true);
CMemoryStream outputStream (1024, 1024, false);
EXPECT (desc.saveToStream (outputStream, defaultSafeFlags, nullptr));
outputStream.end ();
std::string result (reinterpret_cast<const char*> (outputStream.getBuffer ()));
EXPECT (result.size () == str.size ());
EXPECT (result == str);
}
TEST_CASE (UIDescriptionXMLTests, GetViewAttributes)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
auto attributes = desc.getViewAttributes ("view");
EXPECT (attributes);
auto classAttr = attributes->getAttributeValue (UIViewCreator::kAttrClass);
EXPECT (classAttr);
EXPECT (*classAttr == "CViewContainer");
attributes = desc.getViewAttributes ("view not existing");
EXPECT (attributes == nullptr);
}
TEST_CASE (UIDescriptionXMLTests, CollectTemplateViewNames)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
StringPtrList names;
desc.collectTemplateViewNames (names);
EXPECT (names.size () == 1);
EXPECT (*names.front () == std::string ("view"));
}
TEST_CASE (UIDescriptionXMLTests, DuplicateTemplate)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
StringPtrList names;
desc.collectTemplateViewNames (names);
EXPECT (desc.duplicateTemplate ("view not existing", "viewcopy") == false);
EXPECT (desc.duplicateTemplate ("view", "viewcopy"));
EXPECT (desc.addNewTemplate ("view", nullptr) == false);
names.clear ();
desc.collectTemplateViewNames (names);
EXPECT (names.size () == 2);
EXPECT (*names.front () == std::string ("view"));
EXPECT (*names.back () == std::string ("viewcopy"));
}
TEST_CASE (UIDescriptionXMLTests, ChangeTemplateName)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
EXPECT (desc.duplicateTemplate ("view", "viewcopy"));
EXPECT (desc.changeTemplateName ("viewcopy", "copyOfView"));
StringPtrList names;
desc.collectTemplateViewNames (names);
EXPECT (*names.back () == std::string ("copyOfView"));
}
TEST_CASE (UIDescriptionXMLTests, GetTemplateNameFromView)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
Controller controller;
auto view = owned (desc.createView ("view", &controller));
std::string name;
desc.getTemplateNameFromView (view, name);
EXPECT (name == "view");
}
TEST_CASE (UIDescriptionXMLTests, RemoveTemplate)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
EXPECT (desc.removeTemplate ("view which does not exist") == false);
EXPECT (desc.removeTemplate ("view"));
}
TEST_CASE (UIDescriptionXMLTests, AddNewTemplate)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
auto a = makeOwned<UIAttributes> ();
a->setAttribute (UIViewCreator::kAttrClass, "CViewContainer");
EXPECT (desc.addNewTemplate ("addNewTemplate", a));
StringPtrList names;
desc.collectTemplateViewNames (names);
EXPECT (*names.back () == std::string ("addNewTemplate"));
}
TEST_CASE (UIDescriptionXMLTests, StoreRestoreViews)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
Controller controller;
auto view = owned (desc.createView ("view", &controller));
EXPECT (view);
CMemoryStream memoryStream (1024, 1024, false);
std::list<SharedPointer<CView>> restoredView;
UIAttributes customAttributes;
customAttributes.setAttribute ("Test", "Value");
EXPECT (desc.storeViews ({view.cast<CViewContainer> ()->getView (0)}, memoryStream,
&customAttributes));
memoryStream.rewind ();
UIAttributes* customAttributesRestored = nullptr;
EXPECT (desc.restoreViews (memoryStream, restoredView, &customAttributesRestored));
EXPECT (customAttributesRestored);
EXPECT (*customAttributesRestored->getAttributeValue ("Test") == "Value");
}
TEST_CASE (UIDescriptionXMLTests, StoreRestoreViewsAttached)
{
MemoryContentProvider provider (restoreViewUIDesc,
static_cast<uint32_t> (strlen (restoreViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
Controller controller;
auto view = owned (desc.createView ("view", &controller));
EXPECT (view);
CMemoryStream memoryStream (1024, 1024, false);
std::list<SharedPointer<CView>> restoredView;
auto parentContainer = owned (new CViewContainer (CRect (0, 0, 10, 10)));
view->attached (parentContainer);
auto viewToRestore = SharedPointer<CView> (view.cast<CViewContainer> ()->getView (1));
viewToRestore = viewToRestore.cast<CViewContainer> ()->getView (0);
memoryStream.rewind ();
EXPECT (desc.storeViews ({viewToRestore}, memoryStream));
memoryStream.rewind ();
restoredView.clear ();
EXPECT (desc.restoreViews (memoryStream, restoredView));
view->removed (parentContainer);
}
TEST_CASE (UIDescriptionXMLTests, UpdateViewDescription)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
Controller controller;
auto view = owned (desc.createView ("view", &controller));
EXPECT (view);
EXPECT (view->getTransparency () == false);
view->setTransparency (true);
desc.updateViewDescription ("view", view);
auto attr = desc.getViewAttributes ("view");
bool value;
EXPECT (attr->getBooleanAttribute ("transparent", value));
EXPECT (value == true);
}
TEST_CASE (UIDescriptionXMLTests, CustomAttributes)
{
MemoryContentProvider provider (createViewUIDesc,
static_cast<uint32_t> (strlen (createViewUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
auto attr = desc.getCustomAttributes ("Test", false);
EXPECT (attr == nullptr);
attr = desc.getCustomAttributes ("Test", true);
EXPECT (attr);
EXPECT (desc.getCustomAttributes ("Test", false) == attr);
EXPECT (desc.setCustomAttributes ("Test", nullptr) == false);
}
TEST_CASE (UIDescriptionXMLTests, Listeners)
{
MemoryContentProvider provider (completeExample,
static_cast<uint32_t> (strlen (completeExample)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
DescriptionListenerMock mok (UIDescTestCase::TagChanged);
desc.registerListener (&mok);
desc.changeControlTagString ("NewTag", "5", true);
EXPECT (mok.callCount () == 1);
desc.changeControlTagString ("NewTag", "5", false);
EXPECT (mok.callCount () == 2);
desc.changeTagName ("NewTag", "NewTagNew");
EXPECT (mok.callCount () == 3);
desc.removeTag ("NewTagNew");
EXPECT (mok.callCount () == 4);
mok.setTestCase (UIDescTestCase::ColorChanged);
EXPECT (mok.callCount () == 0);
CColor newColor;
desc.changeColor ("NewColor", newColor);
EXPECT (mok.callCount () == 1);
desc.changeColor ("NewColor", newColor);
EXPECT (mok.callCount () == 2);
desc.changeColorName ("NewColor", "NewColorNew");
EXPECT (mok.callCount () == 3);
desc.removeColor ("NewColorNew");
EXPECT (mok.callCount () == 4);
mok.setTestCase (UIDescTestCase::FontChanged);
EXPECT (mok.callCount () == 0);
auto font = makeOwned<CFontDesc> ();
desc.changeFont ("NewFont", font);
EXPECT (mok.callCount () == 1);
desc.changeFont ("NewFont", font);
EXPECT (mok.callCount () == 2);
desc.changeFontName ("NewFont", "NewFontNew");
EXPECT (mok.callCount () == 3);
desc.changeAlternativeFontNames ("NewFontNew", "Hack, Menlo");
EXPECT (mok.callCount () == 4);
desc.removeFont ("NewFontNew");
EXPECT (mok.callCount () == 5);
mok.setTestCase (UIDescTestCase::BitmapChanged);
EXPECT (mok.callCount () == 0);
auto bitmap = makeOwned<CBitmap> (CPoint (10, 10));
desc.changeBitmap ("NewBitmap", "bitmappath");
EXPECT (mok.callCount () == 1);
desc.changeBitmap ("NewBitmap", "bitmappath");
EXPECT (mok.callCount () == 2);
desc.changeBitmapName ("NewBitmap", "NewBitmapNew");
EXPECT (mok.callCount () == 3);
desc.removeBitmap ("NewBitmapNew");
EXPECT (mok.callCount () == 4);
mok.setTestCase (UIDescTestCase::GradientChanged);
EXPECT (mok.callCount () == 0);
auto gradient = owned (CGradient::create (0., 0., newColor, newColor));
desc.changeGradient ("NewGradient", gradient);
EXPECT (mok.callCount () == 1);
desc.changeGradient ("NewGradient", gradient);
EXPECT (mok.callCount () == 2);
desc.changeGradientName ("NewGradient", "NewGradientNew");
EXPECT (mok.callCount () == 3);
desc.removeGradient ("NewGradientNew");
EXPECT (mok.callCount () == 4);
mok.setTestCase (UIDescTestCase::TemplateChanged);
EXPECT (mok.callCount () == 0);
desc.addNewTemplate ("NewTemplate", makeOwned<UIAttributes> ());
EXPECT (mok.callCount () == 1);
desc.changeTemplateName ("NewTemplate", "NewTemplateNew");
EXPECT (mok.callCount () == 2);
desc.duplicateTemplate ("NewTemplateNew", "NewTemplateNewDup");
EXPECT (mok.callCount () == 3);
desc.removeTemplate ("NewTemplateNew");
EXPECT (mok.callCount () == 4);
desc.removeTemplate ("NewTemplateNewDup");
EXPECT (mok.callCount () == 5);
desc.unregisterListener (&mok);
}
TEST_CASE (UIDescriptionXMLTests, FocusSettings)
{
MemoryContentProvider provider (emptyUIDesc, static_cast<uint32_t> (strlen (emptyUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
FocusDrawingSettings fd;
fd.enabled = true;
fd.width = 1.5;
fd.colorName = "FocusColor";
desc.setFocusDrawingSettings (fd);
auto fd2 = desc.getFocusDrawingSettings ();
EXPECT (!(fd != fd2));
}
TEST_CASE (UIDescriptionXMLTests, SharedResources)
{
MemoryContentProvider provider (emptyUIDesc, static_cast<uint32_t> (strlen (emptyUIDesc)));
UIDescription desc (&provider);
EXPECT (desc.parse () == true);
CColor color1;
CColor color2;
EXPECT (desc.getColor ("c1", color1) == false);
EXPECT (desc.getFont ("f1") == nullptr);
EXPECT (desc.getGradient ("g1") == nullptr);
EXPECT (desc.getBitmap ("b1") == nullptr);
MemoryContentProvider resProvider (sharedResourcesUIDesc,
static_cast<uint32_t> (strlen (sharedResourcesUIDesc)));
UIDescription resDesc (&resProvider);
EXPECT (resDesc.parse () == true);
desc.setSharedResources (&resDesc);
EXPECT (desc.getSharedResources () == &resDesc);
EXPECT (desc.getColor ("c1", color1) == true);
EXPECT (resDesc.getColor ("c1", color2) == true);
EXPECT (color1 == color2);
EXPECT (desc.getFont ("f1") != nullptr);
EXPECT (desc.getFont ("f1") == resDesc.getFont ("f1"));
EXPECT (desc.getGradient ("g1") != nullptr);
EXPECT (desc.getGradient ("g1") == resDesc.getGradient ("g1"));
EXPECT (desc.getBitmap ("b1") != nullptr);
EXPECT (desc.getBitmap ("b1") == resDesc.getBitmap ("b1"));
desc.setSharedResources (nullptr);
}
} // VSTGUI
#endif
@@ -0,0 +1,52 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#pragma once
#include "../../../uidescription/iuidescription.h"
#include "../../../uidescription/uiattributes.h"
namespace VSTGUI {
class UIDescriptionAdapter : public IUIDescription
{
public:
CView* createView (UTF8StringPtr name, IController* controller) const override { return nullptr; }
CBitmap* getBitmap (UTF8StringPtr name) const override { return nullptr; }
CFontRef getFont (UTF8StringPtr name) const override { return nullptr; }
bool getColor (UTF8StringPtr name, CColor& color) const override { return false; }
CGradient* getGradient (UTF8StringPtr name) const override { return nullptr; }
int32_t getTagForName (UTF8StringPtr name) const override { return -1; }
IControlListener* getControlListener (UTF8StringPtr name) const override { return nullptr; }
IController* getController () const override { return nullptr; }
UTF8StringPtr lookupColorName (const CColor& color) const override { return nullptr; }
UTF8StringPtr lookupFontName (const CFontRef font) const override { return nullptr; }
UTF8StringPtr lookupBitmapName (const CBitmap* bitmap) const override { return nullptr; }
UTF8StringPtr lookupGradientName (const CGradient* gradient) const override { return nullptr; }
UTF8StringPtr lookupControlTagName (const int32_t tag) const override { return nullptr; }
bool getVariable (UTF8StringPtr name, double& value) const override { return false; }
bool getVariable (UTF8StringPtr name, std::string& value) const override { return false; }
void collectTemplateViewNames (std::list<const std::string*>& names) const override {}
void collectColorNames (std::list<const std::string*>& names) const override {}
void collectFontNames (std::list<const std::string*>& names) const override {}
void collectBitmapNames (std::list<const std::string*>& names) const override {}
void collectGradientNames (std::list<const std::string*>& names) const override {}
void collectControlTagNames (std::list<const std::string*>& names) const override {}
const IViewFactory* getViewFactory () const override { return nullptr; }
bool setCustomAttributes (UTF8StringPtr name, const SharedPointer<UIAttributes>& attr) override
{
return false;
}
SharedPointer<UIAttributes> getCustomAttributes (UTF8StringPtr name) const override
{
return {};
}
};
}
@@ -0,0 +1,58 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/csplashscreen.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CAnimationSplashScreenCreatorTest, SplashBitmap)
{
DummyUIDescription uidesc;
testAttribute<CAnimationSplashScreen> (
kCAnimationSplashScreen, kAttrSplashBitmap, kBitmapName, &uidesc,
[&] (CAnimationSplashScreen* v) { return v->getSplashBitmap () == uidesc.bitmap; });
}
TEST_CASE (CAnimationSplashScreenCreatorTest, SplashOrigin)
{
DummyUIDescription uidesc;
CPoint p (20, 20);
testAttribute<CAnimationSplashScreen> (
kCAnimationSplashScreen, kAttrSplashOrigin, p, &uidesc,
[&] (CAnimationSplashScreen* v) { return v->getSplashRect ().getTopLeft () == p; });
}
TEST_CASE (CAnimationSplashScreenCreatorTest, SplashSize)
{
DummyUIDescription uidesc;
CPoint p (20, 20);
testAttribute<CAnimationSplashScreen> (
kCAnimationSplashScreen, kAttrSplashSize, p, &uidesc,
[&] (CAnimationSplashScreen* v) { return v->getSplashRect ().getSize () == p; });
}
TEST_CASE (CAnimationSplashScreenCreatorTest, AnimationIndex)
{
DummyUIDescription uidesc;
testAttribute<CAnimationSplashScreen> (
kCAnimationSplashScreen, kAttrAnimationIndex, 1, &uidesc,
[&] (CAnimationSplashScreen* v) { return v->getAnimationIndex () == 1; });
}
TEST_CASE (CAnimationSplashScreenCreatorTest, AnimationTime)
{
DummyUIDescription uidesc;
testAttribute<CAnimationSplashScreen> (
kCAnimationSplashScreen, kAttrAnimationTime, 222, &uidesc,
[&] (CAnimationSplashScreen* v) { return v->getAnimationTime () == 222; });
}
} // VSTGUI
@@ -0,0 +1,43 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cknob.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
#if VSTGUI_ENABLE_DEPRECATED_METHODS
TEST_CASE (CAnimKnobCreatorTest, HeightOfOneImage)
{
DummyUIDescription uidesc;
testAttribute<CAnimKnob> (kCAnimKnob, kAttrHeightOfOneImage, 10, &uidesc,
[] (CAnimKnob* v) { return v->getHeightOfOneImage () == 10; });
}
TEST_CASE (CAnimKnobCreatorTest, SubPixmaps)
{
DummyUIDescription uidesc;
testAttribute<CAnimKnob> (kCAnimKnob, kAttrSubPixmaps, 11, &uidesc,
[] (CAnimKnob* v) { return v->getNumSubPixmaps () == 11; });
}
#endif
TEST_CASE (CAnimKnobCreatorTest, InverseBitmap)
{
DummyUIDescription uidesc;
testAttribute<CAnimKnob> (kCAnimKnob, kAttrInverseBitmap, true, &uidesc,
[] (CAnimKnob* v) { return v->getInverseBitmap () == true; });
testAttribute<CAnimKnob> (kCAnimKnob, kAttrInverseBitmap, false, &uidesc,
[] (CAnimKnob* v) { return v->getInverseBitmap () == false; });
}
} // VSTGUI
@@ -0,0 +1,90 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cbuttons.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CCheckBoxCreatorTest, Title)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (kCCheckBox, kAttrTitle, "title", &uidesc,
[] (CCheckBox* b) { return b->getTitle () == "title"; });
}
TEST_CASE (CCheckBoxCreatorTest, Font)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (kCCheckBox, kAttrFont, kFontName, &uidesc,
[&] (CCheckBox* b) { return uidesc.font == b->getFont (); }, true);
}
TEST_CASE (CCheckBoxCreatorTest, FontColor)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (kCCheckBox, kAttrFontColor, kColorName, &uidesc,
[&] (CCheckBox* b) { return b->getFontColor () == uidesc.color; });
}
TEST_CASE (CCheckBoxCreatorTest, BoxFrameColor)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (
kCCheckBox, kAttrBoxframeColor, kColorName, &uidesc,
[&] (CCheckBox* b) { return b->getBoxFrameColor () == uidesc.color; });
}
TEST_CASE (CCheckBoxCreatorTest, BoxFillColor)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (kCCheckBox, kAttrBoxfillColor, kColorName, &uidesc,
[&] (CCheckBox* b) { return b->getBoxFillColor () == uidesc.color; });
}
TEST_CASE (CCheckBoxCreatorTest, CheckmarkColor)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (
kCCheckBox, kAttrCheckmarkColor, kColorName, &uidesc,
[&] (CCheckBox* b) { return b->getCheckMarkColor () == uidesc.color; });
}
TEST_CASE (CCheckBoxCreatorTest, DrawCrossbox)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (kCCheckBox, kAttrDrawCrossbox, true, &uidesc, [&] (CCheckBox* b) {
return b->getStyle () & CCheckBox::kDrawCrossBox;
});
}
TEST_CASE (CCheckBoxCreatorTest, AutoSizeToFit)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (kCCheckBox, kAttrAutosizeToFit, true, &uidesc, [&] (CCheckBox* b) {
return b->getStyle () & CCheckBox::kAutoSizeToFit;
});
}
TEST_CASE (CCheckBoxCreatorTest, FrameWidth)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (kCCheckBox, kAttrFrameWidth, 15., &uidesc,
[&] (CCheckBox* b) { return b->getFrameWidth () == 15.; });
}
TEST_CASE (CCheckBoxCreatorTest, RoundRectRadius)
{
DummyUIDescription uidesc;
testAttribute<CCheckBox> (kCCheckBox, kAttrRoundRectRadius, 12., &uidesc,
[&] (CCheckBox* b) { return b->getRoundRectRadius () == 12.; });
}
} // VSTGUI
@@ -0,0 +1,94 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/ccontrol.h"
#include "../../../../lib/controls/icontrollistener.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
namespace {
struct DummyListener : public IControlListener
{
void valueChanged (CControl* pControl) override {}
};
} // anonymous
TEST_CASE (CControlCreatorTest, DefaultValue)
{
testAttribute<CControl> (kCControl, kAttrDefaultValue, 1., nullptr,
[] (CControl* v) { return v->getDefaultValue () == 1.; });
}
TEST_CASE (CControlCreatorTest, MinValue)
{
testAttribute<CControl> (kCControl, kAttrMinValue, 0.5, nullptr,
[] (CControl* v) { return v->getMin () == 0.5; });
}
TEST_CASE (CControlCreatorTest, MaxValue)
{
testAttribute<CControl> (kCControl, kAttrMaxValue, 0.5, nullptr,
[] (CControl* v) { return v->getMax () == 0.5; });
}
TEST_CASE (CControlCreatorTest, WheelIncValue)
{
testAttribute<CControl> (kCControl, kAttrWheelIncValue, 0.5, nullptr,
[] (CControl* v) { return v->getWheelInc () == 0.5; });
}
TEST_CASE (CControlCreatorTest, TagUnknown)
{
DummyUIDescription uidesc;
testAttribute<CControl> (kCControl, kAttrControlTag, kTagName, &uidesc, [&] (CControl* v) {
return v->getTag () == -1 && v->getListener () == nullptr;
});
}
TEST_CASE (CControlCreatorTest, TagStrEmpty)
{
DummyUIDescription uidesc;
testAttribute<CControl> (kCControl, kAttrControlTag, "", &uidesc, [&] (CControl* v) {
return v->getTag () == -1 && v->getListener () == nullptr;
});
}
TEST_CASE (CControlCreatorTest, TagWithNumber)
{
DummyUIDescription uidesc;
testAttribute<CControl> (kCControl, kAttrControlTag, "5", &uidesc, [&] (CControl* v) {
return v->getTag () == 5 && v->getListener () == nullptr;
});
}
TEST_CASE (CControlCreatorTest, TagNoListener)
{
DummyUIDescription uidesc;
uidesc.tag = 5;
testAttribute<CControl> (
kCControl, kAttrControlTag, kTagName, &uidesc,
[&] (CControl* v) { return v->getTag () == 5 && v->getListener () == nullptr; }, true);
}
TEST_CASE (CControlCreatorTest, TagWithListener)
{
DummyUIDescription uidesc;
DummyListener listener;
uidesc.tag = 5;
uidesc.listener = &listener;
testAttribute<CControl> (
kCControl, kAttrControlTag, kTagName, &uidesc,
[&] (CControl* v) { return v->getTag () == 5 && v->getListener () == &listener; }, true);
}
} // VSTGUI
@@ -0,0 +1,139 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/cgradientview.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CGradientViewCreatorTest, FrameColor)
{
DummyUIDescription uidesc;
testAttribute<CGradientView> (
kCGradientView, kAttrFrameColor, kColorName, &uidesc,
[&] (CGradientView* v) { return v->getFrameColor () == uidesc.color; });
}
TEST_CASE (CGradientViewCreatorTest, GradientAngle)
{
DummyUIDescription uidesc;
testAttribute<CGradientView> (kCGradientView, kAttrGradientAngle, 5., &uidesc,
[&] (CGradientView* v) { return v->getGradientAngle () == 5.; });
}
TEST_CASE (CGradientViewCreatorTest, RoundRectRadius)
{
DummyUIDescription uidesc;
testAttribute<CGradientView> (
kCGradientView, kAttrRoundRectRadius, 35., &uidesc,
[&] (CGradientView* v) { return v->getRoundRectRadius () == 35.; });
}
TEST_CASE (CGradientViewCreatorTest, FrameWidth)
{
DummyUIDescription uidesc;
testAttribute<CGradientView> (kCGradientView, kAttrFrameWidth, 5., &uidesc,
[&] (CGradientView* v) { return v->getFrameWidth () == 5.; });
}
TEST_CASE (CGradientViewCreatorTest, DrawAntialiased)
{
DummyUIDescription uidesc;
testAttribute<CGradientView> (kCGradientView, kAttrDrawAntialiased, true, &uidesc,
[&] (CGradientView* v) { return v->getDrawAntialised (); });
testAttribute<CGradientView> (
kCGradientView, kAttrDrawAntialiased, false, &uidesc,
[&] (CGradientView* v) { return v->getDrawAntialised () == false; });
}
TEST_CASE (CGradientViewCreatorTest, GradientStyle)
{
DummyUIDescription uidesc;
testAttribute<CGradientView> (
kCGradientView, kAttrGradientStyle, "radial", &uidesc, [&] (CGradientView* v) {
return v->getGradientStyle () == CGradientView::kRadialGradient;
});
testAttribute<CGradientView> (
kCGradientView, kAttrGradientStyle, "linear", &uidesc, [&] (CGradientView* v) {
return v->getGradientStyle () == CGradientView::kLinearGradient;
});
}
TEST_CASE (CGradientViewCreatorTest, RadialCenter)
{
DummyUIDescription uidesc;
CPoint p (20, 20);
testAttribute<CGradientView> (kCGradientView, kAttrRadialCenter, p, &uidesc,
[&] (CGradientView* v) { return v->getRadialCenter () == p; });
}
TEST_CASE (CGradientViewCreatorTest, RadialRadius)
{
DummyUIDescription uidesc;
testAttribute<CGradientView> (kCGradientView, kAttrRadialRadius, 25., &uidesc,
[&] (CGradientView* v) { return v->getRadialRadius () == 25.; });
}
TEST_CASE (CGradientViewCreatorTest, Gradient)
{
DummyUIDescription uidesc;
testAttribute<CGradientView> (
kCGradientView, kAttrGradient, kGradientName, &uidesc,
[&] (CGradientView* v) { return v->getGradient () == uidesc.gradient; });
}
TEST_CASE (CGradientViewCreatorTest, GradientStyleValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCGradientView, kAttrGradientStyle, &uidesc, {"radial", "linear"});
}
TEST_CASE (CGradientViewCreatorTest, GradientAngleMinMax)
{
DummyUIDescription uidesc;
testMinMaxValues (kCGradientView, kAttrGradientAngle, &uidesc, 0., 360.);
}
TEST_CASE (CGradientViewCreatorTest, LegacyGradient)
{
DummyUIDescription uidesc;
UIViewFactory factory;
UIAttributes a;
a.setAttribute (kAttrClass, kCGradientView);
a.setAttribute (kAttrGradientStartColor, kColorName);
auto v = owned (factory.createView (a, &uidesc));
auto view = v.cast<CGradientView> ();
EXPECT (view);
EXPECT (view->getGradient () == nullptr);
a.setAttribute (kAttrGradientEndColor, kColorName);
v = owned (factory.createView (a, &uidesc));
view = v.cast<CGradientView> ();
EXPECT (view);
EXPECT (view->getGradient () == nullptr);
a.setDoubleAttribute (kAttrGradientStartColorOffset, 0.);
v = owned (factory.createView (a, &uidesc));
view = v.cast<CGradientView> ();
EXPECT (view);
EXPECT (view->getGradient () == nullptr);
a.setDoubleAttribute (kAttrGradientEndColorOffset, 1.);
v = owned (factory.createView (a, &uidesc));
view = v.cast<CGradientView> ();
EXPECT (view);
EXPECT (view->getGradient ());
}
} // VSTGUI
@@ -0,0 +1,36 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cswitch.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
#if VSTGUI_ENABLE_DEPRECATED_METHODS
TEST_CASE (CHorizontalSwitchCreatorTest, HeightOfOneImage)
{
DummyUIDescription uidesc;
testAttribute<CHorizontalSwitch> (
kCHorizontalSwitch, kAttrHeightOfOneImage, 10, &uidesc,
[] (CHorizontalSwitch* v) { return v->getHeightOfOneImage () == 10; });
}
TEST_CASE (CHorizontalSwitchCreatorTest, SubPixmaps)
{
DummyUIDescription uidesc;
testAttribute<CHorizontalSwitch> (
kCHorizontalSwitch, kAttrSubPixmaps, 11, &uidesc,
[] (CHorizontalSwitch* v) { return v->getNumSubPixmaps () == 11; });
}
#endif
} // VSTGUI
@@ -0,0 +1,34 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cbuttons.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
#if VSTGUI_ENABLE_DEPRECATED_METHODS
TEST_CASE (CKickButtonCreatorTest, HeightOfOneImage)
{
DummyUIDescription uidesc;
testAttribute<CKickButton> (kCKickButton, kAttrHeightOfOneImage, 10, &uidesc,
[] (CKickButton* v) { return v->getHeightOfOneImage () == 10; });
}
TEST_CASE (CKickButtonCreatorTest, SubPixmaps)
{
DummyUIDescription uidesc;
testAttribute<CKickButton> (kCKickButton, kAttrSubPixmaps, 11, &uidesc,
[] (CKickButton* v) { return v->getNumSubPixmaps () == 11; });
}
#endif
} // VSTGUI
@@ -0,0 +1,186 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/cbitmap.h"
#include "../../../../lib/cgradient.h"
#include "../../../../lib/controls/cknob.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CKnobCreatorTest, AngleStart)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrAngleStart, 20., &uidesc, [&] (CKnob* v) {
return static_cast<int32_t> (v->getStartAngle () / Constants::pi * 180.) == 20;
});
}
TEST_CASE (CKnobCreatorTest, AngleRange)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrAngleRange, 100., &uidesc, [&] (CKnob* v) {
return static_cast<int32_t> (v->getRangeAngle () / Constants::pi * 180.) == 100;
});
}
TEST_CASE (CKnobCreatorTest, KnobRange)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrKnobRange, 200., &uidesc,
[&] (CKnob* v) { return v->getKnobRange () == 200.; });
}
TEST_CASE (CKnobCreatorTest, ValueInset)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrValueInset, 10., &uidesc,
[&] (CKnob* v) { return v->getInsetValue () == 10.; });
}
TEST_CASE (CKnobCreatorTest, CoronaInset)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaInset, 10., &uidesc,
[&] (CKnob* v) { return v->getCoronaInset () == 10.; });
}
TEST_CASE (CKnobCreatorTest, ZoomFactor)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrZoomFactor, 10., &uidesc,
[&] (CKnob* v) { return v->getZoomFactor () == 10.; });
}
TEST_CASE (CKnobCreatorTest, HandleLineWidth)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrHandleLineWidth, 10., &uidesc,
[&] (CKnob* v) { return v->getHandleLineWidth () == 10.; });
}
TEST_CASE (CKnobCreatorTest, CoronaColor)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaColor, kColorName, &uidesc,
[&] (CKnob* v) { return v->getCoronaColor () == uidesc.color; });
}
TEST_CASE (CKnobCreatorTest, HandleShadowColor)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrHandleShadowColor, kColorName, &uidesc,
[&] (CKnob* v) { return v->getColorShadowHandle () == uidesc.color; });
}
TEST_CASE (CKnobCreatorTest, HandleColor)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrHandleColor, kColorName, &uidesc,
[&] (CKnob* v) { return v->getColorHandle () == uidesc.color; });
}
TEST_CASE (CKnobCreatorTest, HandleBitmap)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrHandleBitmap, kBitmapName, &uidesc,
[&] (CKnob* v) { return v->getHandleBitmap () == uidesc.bitmap; });
}
TEST_CASE (CKnobCreatorTest, CircleDrawing)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCircleDrawing, true, &uidesc, [&] (CKnob* v) {
return v->getDrawStyle () & CKnob::kHandleCircleDrawing;
});
testAttribute<CKnob> (kCKnob, kAttrCircleDrawing, false, &uidesc, [&] (CKnob* v) {
return !(v->getDrawStyle () & CKnob::kHandleCircleDrawing);
});
}
TEST_CASE (CKnobCreatorTest, CoronaDrawing)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaDrawing, true, &uidesc,
[&] (CKnob* v) { return v->getDrawStyle () & CKnob::kCoronaDrawing; });
testAttribute<CKnob> (kCKnob, kAttrCoronaDrawing, false, &uidesc,
[&] (CKnob* v) { return !(v->getDrawStyle () & CKnob::kCoronaDrawing); });
}
TEST_CASE (CKnobCreatorTest, CoronaFromCenter)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaFromCenter, true, &uidesc,
[&] (CKnob* v) { return v->getDrawStyle () & CKnob::kCoronaFromCenter; });
testAttribute<CKnob> (kCKnob, kAttrCoronaFromCenter, false, &uidesc, [&] (CKnob* v) {
return !(v->getDrawStyle () & CKnob::kCoronaFromCenter);
});
}
TEST_CASE (CKnobCreatorTest, CoronaInverted)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaInverted, true, &uidesc,
[&] (CKnob* v) { return v->getDrawStyle () & CKnob::kCoronaInverted; });
testAttribute<CKnob> (kCKnob, kAttrCoronaInverted, false, &uidesc, [&] (CKnob* v) {
return !(v->getDrawStyle () & CKnob::kCoronaInverted);
});
}
TEST_CASE (CKnobCreatorTest, CoronaDashDot)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaDashDot, true, &uidesc, [&] (CKnob* v) {
return v->getDrawStyle () & CKnob::kCoronaLineDashDot;
});
testAttribute<CKnob> (kCKnob, kAttrCoronaDashDot, false, &uidesc, [&] (CKnob* v) {
return !(v->getDrawStyle () & CKnob::kCoronaLineDashDot);
});
}
TEST_CASE (CKnobCreatorTest, CoronaOutline)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaOutline, true, &uidesc,
[&] (CKnob* v) { return v->getDrawStyle () & CKnob::kCoronaOutline; });
testAttribute<CKnob> (kCKnob, kAttrCoronaOutline, false, &uidesc,
[&] (CKnob* v) { return !(v->getDrawStyle () & CKnob::kCoronaOutline); });
}
TEST_CASE (CKnobCreatorTest, CoronaLineCapButt)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaLineCapButt, true, &uidesc, [&] (CKnob* v) {
return v->getDrawStyle () & CKnob::kCoronaLineCapButt;
});
testAttribute<CKnob> (kCKnob, kAttrCoronaLineCapButt, false, &uidesc, [&] (CKnob* v) {
return !(v->getDrawStyle () & CKnob::kCoronaLineCapButt);
});
}
TEST_CASE (CKnobCreatorTest, SkipHandleDrawing)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrSkipHandleDrawing, true, &uidesc, [&] (CKnob* v) {
return v->getDrawStyle () & CKnob::kSkipHandleDrawing;
});
testAttribute<CKnob> (kCKnob, kAttrSkipHandleDrawing, false, &uidesc, [&] (CKnob* v) {
return !(v->getDrawStyle () & CKnob::kSkipHandleDrawing);
});
}
TEST_CASE (CKnobCreatorTest, CoronaOutlineWithAdd)
{
DummyUIDescription uidesc;
testAttribute<CKnob> (kCKnob, kAttrCoronaOutlineWidthAdd, 10., &uidesc,
[&] (CKnob* v) { return v->getCoronaOutlineWidthAdd () == 10.; });
}
} // VSTGUI
@@ -0,0 +1,23 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/clayeredviewcontainer.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CLayeredViewContainerCreatorTest, ZIndex)
{
testAttribute<CLayeredViewContainer> (
kCLayeredViewContainer, kAttrZIndex, 1, nullptr,
[] (CLayeredViewContainer* v) { return v->getZIndex () == 1; });
}
} // VSTGUI
@@ -0,0 +1,34 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cmoviebitmap.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
#if VSTGUI_ENABLE_DEPRECATED_METHODS
TEST_CASE (CMovieBitmapCreatorTest, HeightOfOneImage)
{
DummyUIDescription uidesc;
testAttribute<CMovieBitmap> (kCMovieBitmap, kAttrHeightOfOneImage, 10, &uidesc,
[] (CMovieBitmap* v) { return v->getHeightOfOneImage () == 10; });
}
TEST_CASE (CMovieBitmapCreatorTest, SubPixmaps)
{
DummyUIDescription uidesc;
testAttribute<CMovieBitmap> (kCMovieBitmap, kAttrSubPixmaps, 11, &uidesc,
[] (CMovieBitmap* v) { return v->getNumSubPixmaps () == 11; });
}
#endif
} // VSTGUI
@@ -0,0 +1,35 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cmoviebutton.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
#if VSTGUI_ENABLE_DEPRECATED_METHODS
TEST_CASE (CMovieButtonCreatorTest, HeightOfOneImage)
{
DummyUIDescription uidesc;
testAttribute<CMovieButton> (kCMovieButton, kAttrHeightOfOneImage, 10, &uidesc,
[] (CMovieButton* v) { return v->getHeightOfOneImage () == 10; });
}
TEST_CASE (CMovieButtonCreatorTest, SubPixmaps)
{
DummyUIDescription uidesc;
testAttribute<CMovieButton> (kCMovieButton, kAttrSubPixmaps, 11, &uidesc,
[] (CMovieButton* v) { return v->getNumSubPixmaps () == 11; });
}
#endif
} // VSTGUI
@@ -0,0 +1,48 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/ctextlabel.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CMultiLineTextLabelCreatorTest, AutoHeight)
{
UIDescriptionAdapter uidesc;
testAttribute<CMultiLineTextLabel> (
kCMultiLineTextLabel, kAttrAutoHeight, true, &uidesc,
[] (CMultiLineTextLabel* v) { return v->getAutoHeight () == true; });
}
TEST_CASE (CMultiLineTextLabelCreatorTest, LineLayout)
{
UIDescriptionAdapter uidesc;
testAttribute<CMultiLineTextLabel> (
kCMultiLineTextLabel, kAttrLineLayout, "truncate", &uidesc, [] (CMultiLineTextLabel* v) {
return v->getLineLayout () == CMultiLineTextLabel::LineLayout::truncate;
});
testAttribute<CMultiLineTextLabel> (
kCMultiLineTextLabel, kAttrLineLayout, "wrap", &uidesc, [] (CMultiLineTextLabel* v) {
return v->getLineLayout () == CMultiLineTextLabel::LineLayout::wrap;
});
testAttribute<CMultiLineTextLabel> (
kCMultiLineTextLabel, kAttrLineLayout, "clip", &uidesc, [] (CMultiLineTextLabel* v) {
return v->getLineLayout () == CMultiLineTextLabel::LineLayout::clip;
});
}
TEST_CASE (CMultiLineTextLabelCreatorTest, LineLayoutPossibleValues)
{
UIDescriptionAdapter uidesc;
testPossibleValues (kCMultiLineTextLabel, kAttrLineLayout, &uidesc,
{"clip", "truncate", "wrap"});
}
} // VSTGUI
@@ -0,0 +1,28 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cbuttons.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (COnOffButtonCreatorTest, Create)
{
UIViewFactory factory;
UIAttributes a;
a.setAttribute (kAttrClass, kCOnOffButton);
auto view = owned (factory.createView (a, nullptr));
auto control = view.cast<COnOffButton> ();
EXPECT (control);
UIAttributes a2;
EXPECT (factory.getAttributesForView (view, nullptr, a2));
}
} // VSTGUI
@@ -0,0 +1,32 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/coptionmenu.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (COptionMenuCreatorTest, PopupStyle)
{
UIDescriptionAdapter uidesc;
testAttribute<COptionMenu> (
kCOptionMenu, kAttrMenuPopupStyle, true, &uidesc,
[] (COptionMenu* v) { return v->getStyle () & COptionMenu::kPopupStyle; });
}
TEST_CASE (COptionMenuCreatorTest, checkStyle)
{
UIDescriptionAdapter uidesc;
testAttribute<COptionMenu> (
kCOptionMenu, kAttrMenuCheckStyle, true, &uidesc,
[] (COptionMenu* v) { return v->getStyle () & COptionMenu::kCheckStyle; });
}
} // VSTGUI
@@ -0,0 +1,165 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cparamdisplay.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CParamDisplayCreatorTest, Font)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (kCParamDisplay, kAttrFont, kFontName, &uiDesc,
[&] (CParamDisplay* v) { return v->getFont () == uiDesc.font; },
true);
}
TEST_CASE (CParamDisplayCreatorTest, FontColor)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrFontColor, kColorName, &uiDesc,
[&] (CParamDisplay* v) { return v->getFontColor () == uiDesc.color; });
}
TEST_CASE (CParamDisplayCreatorTest, BackColor)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrBackColor, kColorName, &uiDesc,
[&] (CParamDisplay* v) { return v->getBackColor () == uiDesc.color; });
}
TEST_CASE (CParamDisplayCreatorTest, FrameColor)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrFrameColor, kColorName, &uiDesc,
[&] (CParamDisplay* v) { return v->getFrameColor () == uiDesc.color; });
}
TEST_CASE (CParamDisplayCreatorTest, ShadowColor)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrShadowColor, kColorName, &uiDesc,
[&] (CParamDisplay* v) { return v->getShadowColor () == uiDesc.color; });
}
TEST_CASE (CParamDisplayCreatorTest, TextInset)
{
DummyUIDescription uiDesc;
CPoint inset (5, 6);
testAttribute<CParamDisplay> (kCParamDisplay, kAttrTextInset, inset, &uiDesc,
[&] (CParamDisplay* v) { return v->getTextInset () == inset; });
}
TEST_CASE (CParamDisplayCreatorTest, FontAntialias)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (kCParamDisplay, kAttrFontAntialias, true, &uiDesc,
[&] (CParamDisplay* v) { return v->getAntialias (); });
testAttribute<CParamDisplay> (kCParamDisplay, kAttrFontAntialias, false, &uiDesc,
[&] (CParamDisplay* v) { return v->getAntialias () == false; });
}
TEST_CASE (CParamDisplayCreatorTest, TextAlignment)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrTextAlignment, "left", &uiDesc,
[&] (CParamDisplay* v) { return v->getHoriAlign () == kLeftText; });
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrTextAlignment, "center", &uiDesc,
[&] (CParamDisplay* v) { return v->getHoriAlign () == kCenterText; });
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrTextAlignment, "right", &uiDesc,
[&] (CParamDisplay* v) { return v->getHoriAlign () == kRightText; });
}
TEST_CASE (CParamDisplayCreatorTest, RoundRectRadius)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrRoundRectRadius, 15., &uiDesc,
[&] (CParamDisplay* v) { return v->getRoundRectRadius () == 15.; });
}
TEST_CASE (CParamDisplayCreatorTest, FrameWidth)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (kCParamDisplay, kAttrFrameWidth, 12., &uiDesc,
[&] (CParamDisplay* v) { return v->getFrameWidth () == 12.; });
}
TEST_CASE (CParamDisplayCreatorTest, TextRotation)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (kCParamDisplay, kAttrTextRotation, 89., &uiDesc,
[&] (CParamDisplay* v) { return v->getTextRotation () == 89.; });
}
TEST_CASE (CParamDisplayCreatorTest, Styles)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrStyle3DIn, true, &uiDesc,
[&] (CParamDisplay* v) { return v->getStyle () & CParamDisplay::k3DIn; });
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrStyle3DOut, true, &uiDesc,
[&] (CParamDisplay* v) { return v->getStyle () & CParamDisplay::k3DOut; });
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrStyleNoFrame, true, &uiDesc,
[&] (CParamDisplay* v) { return v->getStyle () & CParamDisplay::kNoFrame; });
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrStyleNoDraw, true, &uiDesc,
[&] (CParamDisplay* v) { return v->getStyle () & CParamDisplay::kNoDrawStyle; });
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrStyleNoText, true, &uiDesc,
[&] (CParamDisplay* v) { return v->getStyle () & CParamDisplay::kNoTextStyle; });
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrStyleShadowText, true, &uiDesc,
[&] (CParamDisplay* v) { return v->getStyle () & CParamDisplay::kShadowText; });
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrStyleRoundRect, true, &uiDesc,
[&] (CParamDisplay* v) { return v->getStyle () & CParamDisplay::kRoundRectStyle; });
}
TEST_CASE (CParamDisplayCreatorTest, ValuePrecision)
{
DummyUIDescription uiDesc;
testAttribute<CParamDisplay> (kCParamDisplay, kAttrValuePrecision, 3, &uiDesc,
[&] (CParamDisplay* v) { return v->getPrecision () == 3; });
}
TEST_CASE (CParamDisplayCreatorTest, TextRotationMinMax)
{
DummyUIDescription uidesc;
testMinMaxValues (kCParamDisplay, kAttrTextRotation, &uidesc, 0., 360.);
}
TEST_CASE (CParamDisplayCreatorTest, BackgroundOffset)
{
DummyUIDescription uiDesc;
CPoint offset (20, 20);
testAttribute<CParamDisplay> (kCParamDisplay, kAttrBackgroundOffset, offset, &uiDesc,
[&] (CParamDisplay* v) { return v->getBackOffset () == offset; });
}
TEST_CASE (CParamDisplayCreatorTest, ShadowOffset)
{
DummyUIDescription uiDesc;
CPoint offset (15, 9);
testAttribute<CParamDisplay> (
kCParamDisplay, kAttrTextShadowOffset, offset, &uiDesc,
[&] (CParamDisplay* v) { return v->getShadowTextOffset () == offset; });
}
} // VSTGUI
@@ -0,0 +1,35 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cswitch.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
#if VSTGUI_ENABLE_DEPRECATED_METHODS
TEST_CASE (CRockerSwitchCreatorTest, HeightOfOneImage)
{
DummyUIDescription uidesc;
testAttribute<CRockerSwitch> (
kCRockerSwitch, kAttrHeightOfOneImage, 10, &uidesc,
[] (CRockerSwitch* v) { return v->getHeightOfOneImage () == 10; });
}
TEST_CASE (CRockerSwitchCreatorTest, SubPixmaps)
{
DummyUIDescription uidesc;
testAttribute<CRockerSwitch> (kCRockerSwitch, kAttrSubPixmaps, 11, &uidesc,
[] (CRockerSwitch* v) { return v->getNumSubPixmaps () == 11; });
}
#endif
} // VSTGUI
@@ -0,0 +1,99 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/crowcolumnview.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CRowColumnViewCreatorTest, RowStyle)
{
testAttribute<CRowColumnView> (
kCRowColumnView, kAttrRowStyle, true, nullptr,
[] (CRowColumnView* v) { return v->getStyle () == CRowColumnView::kRowStyle; });
}
TEST_CASE (CRowColumnViewCreatorTest, ColumnStyle)
{
testAttribute<CRowColumnView> (
kCRowColumnView, kAttrRowStyle, false, nullptr,
[] (CRowColumnView* v) { return v->getStyle () == CRowColumnView::kColumnStyle; });
}
TEST_CASE (CRowColumnViewCreatorTest, Spacing)
{
testAttribute<CRowColumnView> (kCRowColumnView, kAttrSpacing, 5., nullptr,
[] (CRowColumnView* v) { return v->getSpacing () == 5.; });
}
TEST_CASE (CRowColumnViewCreatorTest, Margin)
{
CRect margin (5, 6, 7, 8);
testAttribute<CRowColumnView> (kCRowColumnView, kAttrMargin, margin, nullptr,
[&] (CRowColumnView* v) { return v->getMargin () == margin; });
}
TEST_CASE (CRowColumnViewCreatorTest, AnimateViewResizing)
{
testAttribute<CRowColumnView> (kCRowColumnView, kAttrAnimateViewResizing, true, nullptr,
[] (CRowColumnView* v) { return v->isAnimateViewResizing (); });
}
TEST_CASE (CRowColumnViewCreatorTest, EqualSizeLayoutStretch)
{
testAttribute<CRowColumnView> (
kCRowColumnView, kAttrEqualSizeLayout, "stretch", nullptr,
[] (CRowColumnView* v) { return v->getLayoutStyle () == CRowColumnView::kStretchEqualy; });
}
TEST_CASE (CRowColumnViewCreatorTest, EqualSizeLayoutCenter)
{
testAttribute<CRowColumnView> (
kCRowColumnView, kAttrEqualSizeLayout, "center", nullptr,
[] (CRowColumnView* v) { return v->getLayoutStyle () == CRowColumnView::kCenterEqualy; });
}
TEST_CASE (CRowColumnViewCreatorTest, EqualSizeLayoutRightBottom)
{
testAttribute<CRowColumnView> (
kCRowColumnView, kAttrEqualSizeLayout, "right-bottom", nullptr, [] (CRowColumnView* v) {
return v->getLayoutStyle () == CRowColumnView::kRightBottomEqualy;
});
}
TEST_CASE (CRowColumnViewCreatorTest, EqualSizeLayoutLeftTop)
{
testAttribute<CRowColumnView> (
kCRowColumnView, kAttrEqualSizeLayout, "left-top", nullptr,
[] (CRowColumnView* v) { return v->getLayoutStyle () == CRowColumnView::kLeftTopEqualy; });
}
TEST_CASE (CRowColumnViewCreatorTest, AnimationTime)
{
testAttribute<CRowColumnView> (
kCRowColumnView, kAttrViewResizeAnimationTime, 100, nullptr,
[] (CRowColumnView* v) { return v->getViewResizeAnimationTime () == 100; });
}
TEST_CASE (CRowColumnViewCreatorTest, EqualSizeLayoutValues)
{
testPossibleValues (kCRowColumnView, kAttrEqualSizeLayout, nullptr,
{"left-top", "stretch", "center", "right-bottom", "top-left", "top-center",
"top-right", "middle-left", "middle-center", "middle-right", "bottom-left",
"bottom-center", "bottom-right"});
}
TEST_CASE (CRowColumnViewCreatorTest, HideClippedSubviews)
{
testAttribute<CRowColumnView> (kCRowColumnView, kAttrHideClippedSubviews, true, nullptr,
[] (CRowColumnView* v) { return v->hideClippedSubviews (); });
}
} // VSTGUI
@@ -0,0 +1,120 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cscrollbar.h"
#include "../../../../lib/cscrollview.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CScrollViewContainerCreatorTest, ContainerSize)
{
CPoint size (100, 100);
testAttribute<CScrollView> (
kCScrollView, kAttrContainerSize, size, nullptr,
[&] (CScrollView* v) { return v->getContainerSize ().getSize () == size; });
}
TEST_CASE (CScrollViewContainerCreatorTest, HorizontalScrollbar)
{
testAttribute<CScrollView> (
kCScrollView, kAttrHorizontalScrollbar, true, nullptr,
[&] (CScrollView* v) { return v->getStyle () & CScrollView::kHorizontalScrollbar; });
}
TEST_CASE (CScrollViewContainerCreatorTest, VerticalScrollbar)
{
testAttribute<CScrollView> (
kCScrollView, kAttrVerticalScrollbar, true, nullptr,
[&] (CScrollView* v) { return v->getStyle () & CScrollView::kVerticalScrollbar; });
}
TEST_CASE (CScrollViewContainerCreatorTest, AutoDragScrolling)
{
testAttribute<CScrollView> (
kCScrollView, kAttrAutoDragScrolling, true, nullptr,
[&] (CScrollView* v) { return v->getStyle () & CScrollView::kAutoDragScrolling; });
}
TEST_CASE (CScrollViewContainerCreatorTest, DontDrawFrame)
{
DummyUIDescription uiDesc;
testAttribute<CScrollView> (kCScrollView, kAttrBordered, true, &uiDesc, [&] (CScrollView* v) {
return v->getStyle () & ~CScrollView::kDontDrawFrame;
});
testAttribute<CScrollView> (kCScrollView, kAttrBordered, false, &uiDesc, [&] (CScrollView* v) {
return v->getStyle () & CScrollView::kDontDrawFrame;
});
}
TEST_CASE (CScrollViewContainerCreatorTest, OverlayScrollbars)
{
testAttribute<CScrollView> (
kCScrollView, kAttrOverlayScrollbars, true, nullptr,
[&] (CScrollView* v) { return v->getStyle () & CScrollView::kOverlayScrollbars; });
}
TEST_CASE (CScrollViewContainerCreatorTest, FollowFocusView)
{
testAttribute<CScrollView> (
kCScrollView, kAttrFollowFocusView, true, nullptr,
[&] (CScrollView* v) { return v->getStyle () & CScrollView::kFollowFocusView; });
}
TEST_CASE (CScrollViewContainerCreatorTest, AutoHideScrollbars)
{
testAttribute<CScrollView> (
kCScrollView, kAttrAutoHideScrollbars, true, nullptr,
[&] (CScrollView* v) { return v->getStyle () & CScrollView::kAutoHideScrollbars; });
}
TEST_CASE (CScrollViewContainerCreatorTest, ScrollbarWidth)
{
testAttribute<CScrollView> (kCScrollView, kAttrScrollbarWidth, 5., nullptr,
[&] (CScrollView* v) { return v->getScrollbarWidth () == 5.; });
}
TEST_CASE (CScrollViewContainerCreatorTest, ScrollbarBackgroundColor)
{
DummyUIDescription uiDesc;
testAttribute<CScrollView> (kCScrollView, kAttrScrollbarBackgroundColor, kColorName, &uiDesc,
[&] (CScrollView* v) {
auto sb = v->getVerticalScrollbar ();
if (!sb)
sb = v->getHorizontalScrollbar ();
return sb->getBackgroundColor () == uiDesc.color;
});
}
TEST_CASE (CScrollViewContainerCreatorTest, ScrollbarFrameColor)
{
DummyUIDescription uiDesc;
testAttribute<CScrollView> (kCScrollView, kAttrScrollbarFrameColor, kColorName, &uiDesc,
[&] (CScrollView* v) {
auto sb = v->getVerticalScrollbar ();
if (!sb)
sb = v->getHorizontalScrollbar ();
return sb->getFrameColor () == uiDesc.color;
});
}
TEST_CASE (CScrollViewContainerCreatorTest, ScrollbarScrollerColor)
{
DummyUIDescription uiDesc;
testAttribute<CScrollView> (kCScrollView, kAttrScrollbarScrollerColor, kColorName, &uiDesc,
[&] (CScrollView* v) {
auto sb = v->getVerticalScrollbar ();
if (!sb)
sb = v->getHorizontalScrollbar ();
return sb->getScrollerColor () == uiDesc.color;
});
}
} // VSTGUI
@@ -0,0 +1,25 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/csearchtextedit.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CSearchTextEditCreatorTest, ClearMarkInset)
{
UIDescriptionAdapter uidesc;
CPoint p (10, 11);
testAttribute<CSearchTextEdit> (
kCSearchTextEdit, kAttrClearMarkInset, p, &uidesc,
[&] (CSearchTextEdit* v) { return v->getClearMarkInset () == p; });
}
} // VSTGUI
@@ -0,0 +1,179 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/csegmentbutton.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CSegmentButtonCreatorTest, Font)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (kCSegmentButton, kAttrFont, kFontName, &uidesc,
[&] (CSegmentButton* v) { return v->getFont () == uidesc.font; },
true);
}
TEST_CASE (CSegmentButtonCreatorTest, Style)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrStyle, "horizontal", &uidesc,
[&] (CSegmentButton* v) { return v->getStyle () == CSegmentButton::Style::kHorizontal; });
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrStyle, "vertical", &uidesc,
[&] (CSegmentButton* v) { return v->getStyle () == CSegmentButton::Style::kVertical; });
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrStyle, "horizontal-inverse", &uidesc, [&] (CSegmentButton* v) {
return v->getStyle () == CSegmentButton::Style::kHorizontalInverse;
});
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrStyle, "vertical-inverse", &uidesc, [&] (CSegmentButton* v) {
return v->getStyle () == CSegmentButton::Style::kVerticalInverse;
});
}
TEST_CASE (CSegmentButtonCreatorTest, SelectionMode)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrSelectionMode, "Single", &uidesc, [&] (CSegmentButton* v) {
return v->getSelectionMode () == CSegmentButton::SelectionMode::kSingle;
});
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrSelectionMode, "Single-Toggle", &uidesc, [&] (CSegmentButton* v) {
return v->getSelectionMode () == CSegmentButton::SelectionMode::kSingleToggle;
});
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrSelectionMode, "Multiple", &uidesc, [&] (CSegmentButton* v) {
return v->getSelectionMode () == CSegmentButton::SelectionMode::kMultiple;
});
testPossibleValues (kCSegmentButton, kAttrSelectionMode, &uidesc,
{"Single", "Single-Toggle", "Multiple"});
}
TEST_CASE (CSegmentButtonCreatorTest, TextColor)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrTextColor, kColorName, &uidesc,
[&] (CSegmentButton* v) { return v->getTextColor () == uidesc.color; });
}
TEST_CASE (CSegmentButtonCreatorTest, TextColorHighlighted)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrTextColorHighlighted, kColorName, &uidesc,
[&] (CSegmentButton* v) { return v->getTextColorHighlighted () == uidesc.color; });
}
TEST_CASE (CSegmentButtonCreatorTest, FrameColor)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrFrameColor, kColorName, &uidesc,
[&] (CSegmentButton* v) { return v->getFrameColor () == uidesc.color; });
}
TEST_CASE (CSegmentButtonCreatorTest, FrameWidth)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (kCSegmentButton, kAttrFrameWidth, 5., &uidesc,
[&] (CSegmentButton* v) { return v->getFrameWidth () == 5.; });
}
TEST_CASE (CSegmentButtonCreatorTest, RoundRadius)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (kCSegmentButton, kAttrRoundRadius, 15., &uidesc,
[&] (CSegmentButton* v) { return v->getRoundRadius () == 15.; });
}
TEST_CASE (CSegmentButtonCreatorTest, TextIconMargin)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (kCSegmentButton, kAttrIconTextMargin, 15., &uidesc,
[&] (CSegmentButton* v) { return v->getTextMargin () == 15; });
}
TEST_CASE (CSegmentButtonCreatorTest, TextAlignment)
{
DummyUIDescription uiDesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrTextAlignment, "left", &uiDesc,
[&] (CSegmentButton* v) { return v->getTextAlignment () == kLeftText; });
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrTextAlignment, "center", &uiDesc,
[&] (CSegmentButton* v) { return v->getTextAlignment () == kCenterText; });
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrTextAlignment, "right", &uiDesc,
[&] (CSegmentButton* v) { return v->getTextAlignment () == kRightText; });
}
TEST_CASE (CSegmentButtonCreatorTest, Gradient)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrGradient, kGradientName, &uidesc,
[&] (CSegmentButton* v) { return v->getGradient () == uidesc.gradient; }, true);
}
TEST_CASE (CSegmentButtonCreatorTest, GradientHighlighted)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrGradientHighlighted, kGradientName, &uidesc,
[&] (CSegmentButton* v) { return v->getGradientHighlighted () == uidesc.gradient; }, true);
}
TEST_CASE (CSegmentButtonCreatorTest, SegmentNames)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (kCSegmentButton, kAttrSegmentNames, "s1,s2,s3", &uidesc,
[&] (CSegmentButton* v) {
EXPECT (v->getSegments ()[0].name == "s1");
EXPECT (v->getSegments ()[1].name == "s2");
EXPECT (v->getSegments ()[2].name == "s3");
return v->getSegments ().size () == 3;
});
}
TEST_CASE (CSegmentButtonCreatorTest, TruncateMode)
{
DummyUIDescription uidesc;
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrTruncateMode, "head", &uidesc, [] (CSegmentButton* v) {
return v->getTextTruncateMode () == CDrawMethods::kTextTruncateHead;
});
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrTruncateMode, "tail", &uidesc, [] (CSegmentButton* v) {
return v->getTextTruncateMode () == CDrawMethods::kTextTruncateTail;
});
testAttribute<CSegmentButton> (
kCSegmentButton, kAttrTruncateMode, "", &uidesc, [] (CSegmentButton* v) {
return v->getTextTruncateMode () == CDrawMethods::kTextTruncateNone;
});
}
TEST_CASE (CSegmentButtonCreatorTest, TruncateModeValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCSegmentButton, kAttrTruncateMode, &uidesc, {"head", "tail", "none"});
}
TEST_CASE (CSegmentButtonCreatorTest, OrientationValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCSegmentButton, kAttrStyle, &uidesc,
{"horizontal", "vertical", "horizontal-inverse", "vertical-inverse"});
}
} // VSTGUI
@@ -0,0 +1,53 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/cshadowviewcontainer.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CShadowViewContainerCreatorTest, ShadowIntensity)
{
DummyUIDescription uidesc;
testAttribute<CShadowViewContainer> (
kCShadowViewContainer, kAttrShadowIntensity, 0.5, &uidesc,
[] (CShadowViewContainer* v) { return v->getShadowIntensity () == 0.5f; });
}
TEST_CASE (CShadowViewContainerCreatorTest, ShadowBlurSize)
{
DummyUIDescription uidesc;
testAttribute<CShadowViewContainer> (
kCShadowViewContainer, kAttrShadowBlurSize, 0.5, &uidesc,
[] (CShadowViewContainer* v) { return v->getShadowBlurSize () == 0.5f; });
}
TEST_CASE (CShadowViewContainerCreatorTest, ShadowOffset)
{
DummyUIDescription uidesc;
CPoint p (20, 20);
testAttribute<CShadowViewContainer> (
kCShadowViewContainer, kAttrShadowOffset, p, &uidesc,
[&] (CShadowViewContainer* v) { return v->getShadowOffset () == p; });
}
TEST_CASE (CShadowViewContainerCreatorTest, ShadowBlurSizeMinMax)
{
DummyUIDescription uidesc;
testMinMaxValues (kCShadowViewContainer, kAttrShadowBlurSize, &uidesc, 0.8, 20);
}
TEST_CASE (CShadowViewContainerCreatorTest, ShadowIntensityMinMax)
{
DummyUIDescription uidesc;
testMinMaxValues (kCShadowViewContainer, kAttrShadowIntensity, &uidesc, 0., 1.);
}
} // VSTGUI
@@ -0,0 +1,183 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cslider.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CSliderCreatorTest, Mode)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrMode, "touch", &uidesc,
[&] (CSlider* v) { return v->getSliderMode () == CSliderMode::Touch; });
testAttribute<CSlider> (kCSlider, kAttrMode, "relative touch", &uidesc, [&] (CSlider* v) {
return v->getSliderMode () == CSliderMode::RelativeTouch;
});
testAttribute<CSlider> (kCSlider, kAttrMode, "free click", &uidesc, [&] (CSlider* v) {
return v->getSliderMode () == CSliderMode::FreeClick;
});
testAttribute<CSlider> (kCSlider, kAttrMode, "ramp", &uidesc,
[&] (CSlider* v) { return v->getSliderMode () == CSliderMode::Ramp; });
testAttribute<CSlider> (kCSlider, kAttrMode, "use global", &uidesc, [&] (CSlider* v) {
return v->getSliderMode () == CSliderMode::UseGlobal;
});
}
TEST_CASE (CSliderCreatorTest, HandleBitmap)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrHandleBitmap, kBitmapName, &uidesc,
[&] (CSlider* v) { return v->getHandle () == uidesc.bitmap; });
}
TEST_CASE (CSliderCreatorTest, HandleOffset)
{
DummyUIDescription uidesc;
CPoint p (20, 20);
testAttribute<CSlider> (kCSlider, kAttrHandleOffset, p, &uidesc,
[&] (CSlider* v) { return v->getOffsetHandle () == p; });
}
TEST_CASE (CSliderCreatorTest, BitmapOffset)
{
DummyUIDescription uidesc;
CPoint p (20, 20);
testAttribute<CSlider> (kCSlider, kAttrBitmapOffset, p, &uidesc,
[&] (CSlider* v) { return v->getBackgroundOffset () == p; });
}
TEST_CASE (CSliderCreatorTest, ZoomFactor)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrZoomFactor, 15., &uidesc,
[&] (CSlider* v) { return v->getZoomFactor () == 15.; });
}
TEST_CASE (CSliderCreatorTest, Orientation)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrOrientation, "horizontal", &uidesc,
[&] (CSlider* v) { return v->getStyle () & CSlider::kHorizontal; });
testAttribute<CSlider> (kCSlider, kAttrOrientation, "vertical", &uidesc,
[&] (CSlider* v) { return v->getStyle () & CSlider::kVertical; });
}
TEST_CASE (CSliderCreatorTest, ReverseOrientation)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrReverseOrientation, true, &uidesc, [&] (CSlider* v) {
auto style = v->getStyle ();
if (style & CSlider::kHorizontal)
return style & CSlider::kRight;
return style & CSlider::kTop;
});
testAttribute<CSlider> (kCSlider, kAttrReverseOrientation, false, &uidesc, [&] (CSlider* v) {
auto style = v->getStyle ();
if (style & CSlider::kHorizontal)
return style & CSlider::kLeft;
return style & CSlider::kBottom;
});
}
TEST_CASE (CSliderCreatorTest, DrawFrame)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrDrawFrame, true, &uidesc,
[&] (CSlider* v) { return v->getDrawStyle () & CSlider::kDrawFrame; });
testAttribute<CSlider> (kCSlider, kAttrDrawFrame, false, &uidesc, [&] (CSlider* v) {
return !(v->getDrawStyle () & CSlider::kDrawFrame);
});
}
TEST_CASE (CSliderCreatorTest, DrawBack)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrDrawBack, true, &uidesc,
[&] (CSlider* v) { return v->getDrawStyle () & CSlider::kDrawBack; });
testAttribute<CSlider> (kCSlider, kAttrDrawBack, false, &uidesc, [&] (CSlider* v) {
return !(v->getDrawStyle () & CSlider::kDrawBack);
});
}
TEST_CASE (CSliderCreatorTest, DrawValue)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrDrawValue, true, &uidesc,
[&] (CSlider* v) { return v->getDrawStyle () & CSlider::kDrawValue; });
testAttribute<CSlider> (kCSlider, kAttrDrawValue, false, &uidesc, [&] (CSlider* v) {
return !(v->getDrawStyle () & CSlider::kDrawValue);
});
}
TEST_CASE (CSliderCreatorTest, DrawValueFromCenter)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrDrawValueFromCenter, true, &uidesc, [&] (CSlider* v) {
return v->getDrawStyle () & CSlider::kDrawValueFromCenter;
});
testAttribute<CSlider> (kCSlider, kAttrDrawValueFromCenter, false, &uidesc, [&] (CSlider* v) {
return !(v->getDrawStyle () & CSlider::kDrawValueFromCenter);
});
}
TEST_CASE (CSliderCreatorTest, DrawValueInverted)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrDrawValueInverted, true, &uidesc, [&] (CSlider* v) {
return v->getDrawStyle () & CSlider::kDrawInverted;
});
testAttribute<CSlider> (kCSlider, kAttrDrawValueInverted, false, &uidesc, [&] (CSlider* v) {
return !(v->getDrawStyle () & CSlider::kDrawInverted);
});
}
TEST_CASE (CSliderCreatorTest, FrameColor)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrDrawFrameColor, kColorName, &uidesc,
[&] (CSlider* v) { return v->getFrameColor () == uidesc.color; });
}
TEST_CASE (CSliderCreatorTest, BackColor)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrDrawBackColor, kColorName, &uidesc,
[&] (CSlider* v) { return v->getBackColor () == uidesc.color; });
}
TEST_CASE (CSliderCreatorTest, ValueColor)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrDrawValueColor, kColorName, &uidesc,
[&] (CSlider* v) { return v->getValueColor () == uidesc.color; });
}
TEST_CASE (CSliderCreatorTest, OrientationValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCSlider, kAttrOrientation, &uidesc, {"horizontal", "vertical"});
}
TEST_CASE (CSliderCreatorTest, ModeValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCSlider, kAttrMode, &uidesc,
{"touch", "relative touch", "free click", "ramp", "use global"});
}
TEST_CASE (CSliderCreatorTest, FrameWidth)
{
DummyUIDescription uidesc;
testAttribute<CSlider> (kCSlider, kAttrFrameWidth, 10, &uidesc,
[&] (CSlider* v) { return v->getFrameWidth () == 10; });
}
} // VSTGUI
@@ -0,0 +1,63 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/csplitview.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CSplitViewCreatorTest, SeparatorWidth)
{
testAttribute<CSplitView> (kCSplitView, kAttrSeparatorWidth, 123, nullptr,
[] (CSplitView* v) { return v->getSeparatorWidth () == 123; });
}
TEST_CASE (CSplitViewCreatorTest, Orientation)
{
DummyUIDescription uidesc;
testAttribute<CSplitView> (
kCSplitView, kAttrOrientation, "horizontal", &uidesc,
[&] (CSplitView* v) { return v->getStyle () == CSplitView::kHorizontal; });
testAttribute<CSplitView> (
kCSplitView, kAttrOrientation, "vertical", &uidesc,
[&] (CSplitView* v) { return v->getStyle () == CSplitView::kVertical; });
}
TEST_CASE (CSplitViewCreatorTest, ResizeMethod)
{
DummyUIDescription uidesc;
testAttribute<CSplitView> (
kCSplitView, kAttrResizeMethod, "first", &uidesc,
[&] (CSplitView* v) { return v->getResizeMethod () == CSplitView::kResizeFirstView; });
testAttribute<CSplitView> (
kCSplitView, kAttrResizeMethod, "second", &uidesc,
[&] (CSplitView* v) { return v->getResizeMethod () == CSplitView::kResizeSecondView; });
testAttribute<CSplitView> (
kCSplitView, kAttrResizeMethod, "last", &uidesc,
[&] (CSplitView* v) { return v->getResizeMethod () == CSplitView::kResizeLastView; });
testAttribute<CSplitView> (kCSplitView, kAttrResizeMethod, "all", &uidesc, [&] (CSplitView* v) {
return v->getResizeMethod () == CSplitView::kResizeAllViews;
});
}
TEST_CASE (CSplitViewCreatorTest, OrientationValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCSplitView, kAttrOrientation, &uidesc, {"horizontal", "vertical"});
}
TEST_CASE (CSplitViewCreatorTest, ResizeMethodValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCSplitView, kAttrResizeMethod, &uidesc,
{"first", "second", "last", "all"});
}
} // VSTGUI
@@ -0,0 +1,213 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cbuttons.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CTextButtonCreatorTest, Title)
{
DummyUIDescription uidesc;
UTF8String title ("Title");
testAttribute<CTextButton> (kCTextButton, kAttrTitle, title, &uidesc,
[&] (CTextButton* v) { return v->getTitle () == title; });
}
TEST_CASE (CTextButtonCreatorTest, Font)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (kCTextButton, kAttrFont, kFontName, &uidesc,
[&] (CTextButton* v) { return v->getFont () == uidesc.font; },
true);
}
TEST_CASE (CTextButtonCreatorTest, TextColor)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (
kCTextButton, kAttrTextColor, kColorName, &uidesc,
[&] (CTextButton* v) { return v->getTextColor () == uidesc.color; });
}
TEST_CASE (CTextButtonCreatorTest, TextColorHighlighted)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (
kCTextButton, kAttrTextColorHighlighted, kColorName, &uidesc,
[&] (CTextButton* v) { return v->getTextColorHighlighted () == uidesc.color; });
}
TEST_CASE (CTextButtonCreatorTest, FrameColor)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (
kCTextButton, kAttrFrameColor, kColorName, &uidesc,
[&] (CTextButton* v) { return v->getFrameColor () == uidesc.color; });
}
TEST_CASE (CTextButtonCreatorTest, FrameColorHighlighted)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (
kCTextButton, kAttrFrameColorHighlighted, kColorName, &uidesc,
[&] (CTextButton* v) { return v->getFrameColorHighlighted () == uidesc.color; });
}
TEST_CASE (CTextButtonCreatorTest, FrameWidth)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (kCTextButton, kAttrFrameWidth, 5., &uidesc,
[&] (CTextButton* v) { return v->getFrameWidth () == 5.; });
}
TEST_CASE (CTextButtonCreatorTest, RoundRadius)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (kCTextButton, kAttrRoundRadius, 5., &uidesc,
[&] (CTextButton* v) { return v->getRoundRadius () == 5.; });
}
TEST_CASE (CTextButtonCreatorTest, IconTextMargin)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (kCTextButton, kAttrIconTextMargin, 5., &uidesc,
[&] (CTextButton* v) { return v->getTextMargin () == 5.; });
}
TEST_CASE (CTextButtonCreatorTest, KickStyle)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (kCTextButton, kAttrKickStyle, true, &uidesc, [&] (CTextButton* v) {
return v->getStyle () == CTextButton::kKickStyle;
});
testAttribute<CTextButton> (kCTextButton, kAttrKickStyle, false, &uidesc, [&] (CTextButton* v) {
return v->getStyle () == CTextButton::kOnOffStyle;
});
}
TEST_CASE (CTextButtonCreatorTest, Icon)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (kCTextButton, kAttrIcon, kBitmapName, &uidesc,
[&] (CTextButton* v) { return v->getIcon () == uidesc.bitmap; });
}
TEST_CASE (CTextButtonCreatorTest, IconHighlighted)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (
kCTextButton, kAttrIconHighlighted, kBitmapName, &uidesc,
[&] (CTextButton* v) { return v->getIconHighlighted () == uidesc.bitmap; });
}
TEST_CASE (CTextButtonCreatorTest, IconPosition)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (
kCTextButton, kAttrIconPosition, "left", &uidesc,
[&] (CTextButton* v) { return v->getIconPosition () == CDrawMethods::kIconLeft; });
testAttribute<CTextButton> (
kCTextButton, kAttrIconPosition, "right", &uidesc,
[&] (CTextButton* v) { return v->getIconPosition () == CDrawMethods::kIconRight; });
testAttribute<CTextButton> (
kCTextButton, kAttrIconPosition, "center above text", &uidesc,
[&] (CTextButton* v) { return v->getIconPosition () == CDrawMethods::kIconCenterAbove; });
testAttribute<CTextButton> (
kCTextButton, kAttrIconPosition, "center below text", &uidesc,
[&] (CTextButton* v) { return v->getIconPosition () == CDrawMethods::kIconCenterBelow; });
}
TEST_CASE (CTextButtonCreatorTest, TextAlignment)
{
DummyUIDescription uiDesc;
testAttribute<CTextButton> (
kCTextButton, kAttrTextAlignment, "left", &uiDesc,
[&] (CTextButton* v) { return v->getTextAlignment () == kLeftText; });
testAttribute<CTextButton> (
kCTextButton, kAttrTextAlignment, "center", &uiDesc,
[&] (CTextButton* v) { return v->getTextAlignment () == kCenterText; });
testAttribute<CTextButton> (
kCTextButton, kAttrTextAlignment, "right", &uiDesc,
[&] (CTextButton* v) { return v->getTextAlignment () == kRightText; });
}
TEST_CASE (CTextButtonCreatorTest, Gradient)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (
kCTextButton, kAttrGradient, kGradientName, &uidesc,
[&] (CTextButton* v) { return v->getGradient () == uidesc.gradient; });
}
TEST_CASE (CTextButtonCreatorTest, GradientHighlighted)
{
DummyUIDescription uidesc;
testAttribute<CTextButton> (
kCTextButton, kAttrGradientHighlighted, kGradientName, &uidesc,
[&] (CTextButton* v) { return v->getGradientHighlighted () == uidesc.gradient; });
}
TEST_CASE (CTextButtonCreatorTest, IconPositionValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCTextButton, kAttrIconPosition, &uidesc,
{"left", "right", "center above text", "center below text"});
}
TEST_CASE (CTextButtonCreatorTest, LegacyGradient)
{
auto defTB = owned (new CTextButton (CRect (0, 0, 100, 20), nullptr, -1, ""));
DummyUIDescription uidesc;
UIViewFactory factory;
UIAttributes a;
a.setAttribute (kAttrClass, kCTextButton);
a.setAttribute (kAttrGradientStartColor, kColorName);
auto v = owned (factory.createView (a, &uidesc));
auto view = v.cast<CTextButton> ();
EXPECT (view);
EXPECT (*view->getGradient () == *defTB->getGradient ());
EXPECT (*view->getGradientHighlighted () == *defTB->getGradientHighlighted ());
a.setAttribute (kAttrGradientStartColorHighlighted, kColorName);
v = owned (factory.createView (a, &uidesc));
view = v.cast<CTextButton> ();
EXPECT (view);
EXPECT (*view->getGradient () == *defTB->getGradient ());
EXPECT (*view->getGradientHighlighted () == *defTB->getGradientHighlighted ());
a.setAttribute (kAttrGradientEndColor, kColorName);
v = owned (factory.createView (a, &uidesc));
view = v.cast<CTextButton> ();
EXPECT (view);
EXPECT (*view->getGradient () == *defTB->getGradient ());
EXPECT (*view->getGradientHighlighted () == *defTB->getGradientHighlighted ());
a.setAttribute (kAttrGradientEndColorHighlighted, kColorName);
v = owned (factory.createView (a, &uidesc));
view = v.cast<CTextButton> ();
EXPECT (view);
EXPECT (*view->getGradient () != *defTB->getGradient ());
EXPECT (*view->getGradientHighlighted () != *defTB->getGradientHighlighted ());
UIAttributes a2;
factory.getAttributesForView (view, &uidesc, a2);
auto str = a2.getAttributeValue (kAttrGradient);
EXPECT (str);
str = a2.getAttributeValue (kAttrGradientHighlighted);
EXPECT (str);
}
} // VSTGUI
@@ -0,0 +1,47 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/ctextedit.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CTextEditCreatorTest, ImmediateTextChange)
{
UIDescriptionAdapter uidesc;
testAttribute<CTextEdit> (kCTextEdit, kAttrImmediateTextChange, true, &uidesc,
[] (CTextEdit* v) { return v->getImmediateTextChange (); });
}
TEST_CASE (CTextEditCreatorTest, DoubleClick)
{
UIDescriptionAdapter uidesc;
testAttribute<CTextEdit> (kCTextEdit, kAttrStyleDoubleClick, true, &uidesc, [] (CTextEdit* v) {
return v->getStyle () & CTextEdit::kDoubleClickStyle;
});
}
TEST_CASE (CTextEditCreatorTest, SecureStyle)
{
DummyUIDescription uidesc;
testAttribute<CTextEdit> (kCTextEdit, kAttrSecureStyle, true, &uidesc,
[&] (CTextEdit* v) { return v->getSecureStyle () == true; });
}
TEST_CASE (CTextEditCreatorTest, PlaceholderTitle)
{
DummyUIDescription uidesc;
auto testValue = "This is a placeholder";
testAttribute<CTextEdit> (
kCTextEdit, kAttrPlaceholderTitle, testValue, &uidesc,
[&] (CTextEdit* b) { return b->getPlaceholderString () == testValue; });
}
} // VSTGUI
@@ -0,0 +1,47 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/ctextlabel.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CTextLabelCreatorTest, Title)
{
UIDescriptionAdapter uidesc;
testAttribute<CTextLabel> (kCTextLabel, kAttrTitle, "Title", &uidesc,
[] (CTextLabel* v) { return v->getText () == "Title"; });
}
TEST_CASE (CTextLabelCreatorTest, TitleWithNewLines)
{
UIDescriptionAdapter uidesc;
const auto title = "This\\nIs\\nA Title";
testAttribute<CTextLabel> (kCTextLabel, kAttrTitle, title, &uidesc, [&] (CTextLabel* v) {
return v->getText () == "This\nIs\nA Title";
});
}
TEST_CASE (CTextLabelCreatorTest, TruncateMode)
{
UIDescriptionAdapter uidesc;
testAttribute<CTextLabel> (kCTextLabel, kAttrTruncateMode, "head", &uidesc, [] (CTextLabel* v) {
return v->getTextTruncateMode () == CTextLabel::kTruncateHead;
});
testAttribute<CTextLabel> (kCTextLabel, kAttrTruncateMode, "tail", &uidesc, [] (CTextLabel* v) {
return v->getTextTruncateMode () == CTextLabel::kTruncateTail;
});
testAttribute<CTextLabel> (kCTextLabel, kAttrTruncateMode, "", &uidesc, [] (CTextLabel* v) {
return v->getTextTruncateMode () == CTextLabel::kTruncateNone;
});
testPossibleValues (kCTextLabel, kAttrTruncateMode, &uidesc, {"head", "tail", "none"});
}
} // VSTGUI
@@ -0,0 +1,47 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cswitch.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
#if VSTGUI_ENABLE_DEPRECATED_METHODS
TEST_CASE (CVerticalSwitchCreatorTest, HeightOfOneImage)
{
DummyUIDescription uidesc;
testAttribute<CVerticalSwitch> (
kCVerticalSwitch, kAttrHeightOfOneImage, 10, &uidesc,
[] (CVerticalSwitch* v) { return v->getHeightOfOneImage () == 10; });
}
TEST_CASE (CVerticalSwitchCreatorTest, SubPixmaps)
{
DummyUIDescription uidesc;
testAttribute<CVerticalSwitch> (
kCVerticalSwitch, kAttrSubPixmaps, 11, &uidesc,
[] (CVerticalSwitch* v) { return v->getNumSubPixmaps () == 11; });
}
#endif
TEST_CASE (CVerticalSwitchCreatorTest, InverseBitmap)
{
DummyUIDescription uidesc;
testAttribute<CVerticalSwitch> (
kCVerticalSwitch, kAttrInverseBitmap, true, &uidesc,
[] (CVerticalSwitch* v) { return v->getInverseBitmap () == true; });
testAttribute<CVerticalSwitch> (
kCVerticalSwitch, kAttrInverseBitmap, false, &uidesc,
[] (CVerticalSwitch* v) { return v->getInverseBitmap () == false; });
}
} // VSTGUI
@@ -0,0 +1,50 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/cstring.h"
#include "../../../../lib/cviewcontainer.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CViewContainerCreatorTest, BackgroundColor)
{
DummyUIDescription uidesc;
testAttribute<CViewContainer> (
kCViewContainer, kAttrBackgroundColor, kColorName, &uidesc,
[&] (CViewContainer* v) { return v->getBackgroundColor () == uidesc.color; });
testAttribute<CViewContainer> (
kCViewContainer, kAttrBackgroundColor, kColorName, &uidesc,
[&] (CViewContainer* v) { return v->getBackgroundColor () == uidesc.color; }, true);
}
TEST_CASE (CViewContainerCreatorTest, BackgroundColorDrawStyle)
{
DummyUIDescription uidesc;
testAttribute<CViewContainer> (
kCViewContainer, kAttrBackgroundColorDrawStyle, "stroked", &uidesc,
[] (CViewContainer* v) { return v->getBackgroundColorDrawStyle () == kDrawStroked; });
testAttribute<CViewContainer> (
kCViewContainer, kAttrBackgroundColorDrawStyle, "filled", &uidesc,
[] (CViewContainer* v) { return v->getBackgroundColorDrawStyle () == kDrawFilled; });
testAttribute<CViewContainer> (kCViewContainer, kAttrBackgroundColorDrawStyle,
"filled and stroked", &uidesc, [] (CViewContainer* v) {
return v->getBackgroundColorDrawStyle () ==
kDrawFilledAndStroked;
});
}
TEST_CASE (CViewContainerCreatorTest, BackgroundColorDrawStyleValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCViewContainer, kAttrBackgroundColorDrawStyle, &uidesc,
{"stroked", "filled", "filled and stroked"});
}
} // VSTGUI
@@ -0,0 +1,149 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/cbitmap.h"
#include "../../../../lib/cstring.h"
#include "../../../../lib/cview.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
namespace {
bool getViewAttributeString (CView* view, const CViewAttributeID attrID, std::string& value)
{
uint32_t attrSize = 0;
if (view->getAttributeSize (attrID, attrSize))
{
char* cstr = new char[attrSize + 1];
if (view->getAttribute (attrID, attrSize, cstr, attrSize))
value = cstr;
else
value = "";
delete[] cstr;
return true;
}
return false;
}
} // anonymous
TEST_CASE (CViewCreatorTest, Origin)
{
CPoint origin (20, 20);
testAttribute<CView> (kCView, kAttrOrigin, origin, nullptr,
[&] (CView* v) { return v->getViewSize ().getTopLeft () == origin; });
}
TEST_CASE (CViewCreatorTest, Size)
{
CPoint size (20, 20);
testAttribute<CView> (kCView, kAttrSize, size, nullptr,
[&] (CView* v) { return v->getViewSize ().getSize () == size; });
}
TEST_CASE (CViewCreatorTest, Bitmap)
{
DummyUIDescription uiDesc;
testAttribute<CView> (kCView, kAttrBitmap, kBitmapName, &uiDesc,
[&] (CView* v) { return v->getBackground () == uiDesc.bitmap; });
}
TEST_CASE (CViewCreatorTest, DisabledBitmap)
{
DummyUIDescription uiDesc;
testAttribute<CView> (kCView, kAttrDisabledBitmap, kBitmapName, &uiDesc,
[&] (CView* v) { return v->getDisabledBackground () == uiDesc.bitmap; });
}
TEST_CASE (CViewCreatorTest, Transparent)
{
testAttribute<CView> (kCView, kAttrTransparent, true, nullptr,
[&] (CView* v) { return v->getTransparency (); });
testAttribute<CView> (kCView, kAttrTransparent, false, nullptr,
[&] (CView* v) { return v->getTransparency () == false; });
}
TEST_CASE (CViewCreatorTest, MouseEnabled)
{
testAttribute<CView> (kCView, kAttrMouseEnabled, true, nullptr,
[&] (CView* v) { return v->getMouseEnabled (); });
testAttribute<CView> (kCView, kAttrMouseEnabled, false, nullptr,
[&] (CView* v) { return v->getMouseEnabled () == false; });
}
TEST_CASE (CViewCreatorTest, Autosize)
{
testAttribute<CView> (kCView, kAttrAutosize, "left ", nullptr,
[&] (CView* v) { return v->getAutosizeFlags () & kAutosizeLeft; });
testAttribute<CView> (kCView, kAttrAutosize, "top ", nullptr,
[&] (CView* v) { return v->getAutosizeFlags () & kAutosizeTop; });
testAttribute<CView> (kCView, kAttrAutosize, "right ", nullptr,
[&] (CView* v) { return v->getAutosizeFlags () & kAutosizeRight; });
testAttribute<CView> (kCView, kAttrAutosize, "bottom ", nullptr,
[&] (CView* v) { return v->getAutosizeFlags () & kAutosizeBottom; });
testAttribute<CView> (kCView, kAttrAutosize, "row ", nullptr,
[&] (CView* v) { return v->getAutosizeFlags () & kAutosizeRow; });
testAttribute<CView> (kCView, kAttrAutosize, "column ", nullptr,
[&] (CView* v) { return v->getAutosizeFlags () & kAutosizeColumn; });
}
TEST_CASE (CViewCreatorTest, Tooltip)
{
std::string tooltipStr = "This is a tooltip";
testAttribute<CView> (kCView, kAttrTooltip, tooltipStr.c_str (), nullptr, [&] (CView* v) {
std::string str;
EXPECT (getViewAttributeString (v, kCViewTooltipAttribute, str));
return str == tooltipStr;
});
UIViewFactory factory;
UIAttributes a;
a.setAttribute (kAttrClass, kCView);
a.setAttribute (kAttrTooltip, "");
auto view = owned (factory.createView (a, nullptr));
std::string str;
EXPECT (getViewAttributeString (view, kCViewTooltipAttribute, str) == false);
}
TEST_CASE (CViewCreatorTest, CustomViewName)
{
std::string customViewName = "CustomView";
testAttribute<CView> (kCView, kAttrCustomViewName, customViewName.c_str (), nullptr,
[&] (CView* v) {
std::string str;
EXPECT (getViewAttributeString (v, 'uicv', str));
return str == customViewName;
});
}
TEST_CASE (CViewCreatorTest, SubControllerName)
{
std::string subControllerName = "SubController";
testAttribute<CView> (kCView, kAttrSubController, subControllerName.c_str (), nullptr,
[&] (CView* v) {
std::string str;
EXPECT (getViewAttributeString (v, 'uisc', str));
return str == subControllerName;
});
}
TEST_CASE (CViewCreatorTest, Opacity)
{
testAttribute<CView> (kCView, kAttrOpacity, 0.5, nullptr,
[&] (CView* v) { return v->getAlphaValue () == 0.5; });
}
TEST_CASE (CViewCreatorTest, OpacityValueRange)
{
testMinMaxValues (kCView, kAttrOpacity, nullptr, 0., 1.);
}
} // VSTGUI
@@ -0,0 +1,54 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cvumeter.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CVuMeterCreatorTest, OffBitmap)
{
DummyUIDescription uidesc;
testAttribute<CVuMeter> (kCVuMeter, kAttrOffBitmap, kBitmapName, &uidesc,
[&] (CVuMeter* v) { return v->getOffBitmap () == uidesc.bitmap; });
}
TEST_CASE (CVuMeterCreatorTest, Orientation)
{
DummyUIDescription uidesc;
testAttribute<CVuMeter> (kCVuMeter, kAttrOrientation, "horizontal", &uidesc, [&] (CVuMeter* v) {
return v->getStyle () == CVuMeter::Style::kHorizontal;
});
testAttribute<CVuMeter> (kCVuMeter, kAttrOrientation, "vertical", &uidesc, [&] (CVuMeter* v) {
return v->getStyle () == CVuMeter::Style::kVertical;
});
}
TEST_CASE (CVuMeterCreatorTest, NumLed)
{
DummyUIDescription uidesc;
testAttribute<CVuMeter> (kCVuMeter, kAttrNumLed, 5, &uidesc,
[&] (CVuMeter* v) { return v->getNbLed () == 5; });
}
TEST_CASE (CVuMeterCreatorTest, DecreaseStepValue)
{
DummyUIDescription uidesc;
testAttribute<CVuMeter> (kCVuMeter, kAttrDecreaseStepValue, 15., &uidesc,
[&] (CVuMeter* v) { return v->getDecreaseStepValue () == 15.; });
}
TEST_CASE (CVuMeterCreatorTest, OrientationValues)
{
DummyUIDescription uidesc;
testPossibleValues (kCVuMeter, kAttrOrientation, &uidesc, {"horizontal", "vertical"});
}
} // VSTGUI
@@ -0,0 +1,30 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cxypad.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (CXYPadCreatorTest, Create)
{
DummyUIDescription uidesc;
UIViewFactory factory;
UIAttributes a;
a.setAttribute (kAttrClass, kCXYPad);
auto view = owned (factory.createView (a, &uidesc));
auto control = view.cast<CXYPad> ();
EXPECT (control);
UIAttributes a2;
EXPECT (factory.getAttributesForView (view, &uidesc, a2));
}
} // VSTGUI
@@ -0,0 +1,287 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#pragma once
#include "../../../../lib/cbitmap.h"
#include "../../../../lib/cgradient.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewcreator.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../uidescriptionadapter.h"
namespace VSTGUI {
constexpr IdStringPtr kColorName = "MyColor";
constexpr IdStringPtr kFontName = "MyFont";
constexpr IdStringPtr kBitmapName = "MyBitmap";
constexpr IdStringPtr kGradientName = "MyGradient";
constexpr IdStringPtr kTagName = "tagname";
class DummyUIDescription : public UIDescriptionAdapter
{
public:
bool getColor (UTF8StringPtr name, CColor& c) const override
{
if (UTF8StringView (name) == kColorName)
{
c = this->color;
return true;
}
return false;
}
UTF8StringPtr lookupColorName (const CColor& c) const override
{
if (this->color == c)
return kColorName;
return nullptr;
}
CFontRef getFont (UTF8StringPtr name) const override
{
if (UTF8StringView (name) == kFontName)
return font;
return nullptr;
}
UTF8StringPtr lookupFontName (const CFontRef f) const override
{
if (f == this->font)
return kFontName;
return nullptr;
}
CBitmap* getBitmap (UTF8StringPtr name) const override
{
if (UTF8StringView (name) == kBitmapName)
return bitmap;
return nullptr;
}
UTF8StringPtr lookupBitmapName (const CBitmap* inBitmap) const override
{
if (inBitmap == bitmap)
return kBitmapName;
return nullptr;
}
CGradient* getGradient (UTF8StringPtr name) const override
{
if (UTF8StringView (name) == kGradientName)
return gradient;
return nullptr;
}
UTF8StringPtr lookupGradientName (const CGradient* g) const override
{
if (g == this->gradient)
return kGradientName;
return nullptr;
}
int32_t getTagForName (UTF8StringPtr name) const override
{
if (UTF8StringView (name) == kTagName)
return tag;
return -1;
}
UTF8StringPtr lookupControlTagName (const int32_t t) const override
{
if (this->tag != -1 && t == this->tag)
return kTagName;
return nullptr;
}
IControlListener* getControlListener (UTF8StringPtr name) const override
{
if (UTF8StringView (name) == kTagName)
return listener;
return nullptr;
}
int32_t tag {-1};
CColor color {20, 30, 50, 255};
SharedPointer<CFontDesc> font = owned (new CFontDesc ("Arial", 12));
SharedPointer<CBitmap> bitmap = owned (new CBitmap (1, 1));
SharedPointer<CGradient> gradient =
owned (CGradient::create (0, 1, kBlackCColor, kWhiteCColor));
IControlListener* listener {nullptr};
};
inline void testPossibleValues (const IdStringPtr className, const std::string& attrName,
IUIDescription* desc, UIViewFactory::StringList expectedValues)
{
UIViewFactory factory;
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, className);
auto view = owned (factory.createView (a, desc));
UIViewFactory::StringPtrList values;
EXPECT (factory.getPossibleAttributeListValues (view, attrName, values));
for (auto& v : expectedValues)
{
EXPECT (std::find_if (values.begin (), values.end (),
[&] (const UIViewFactory::StringPtrList::value_type& value) {
return *value == v;
}) != values.end ());
}
EXPECT (values.size () == expectedValues.size ());
}
inline void testMinMaxValues (const IdStringPtr className, const std::string& attrName,
IUIDescription* desc, double minValue, double maxValue)
{
UIViewFactory factory;
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, className);
auto view = owned (factory.createView (a, desc));
double min, max;
EXPECT (factory.getAttributeValueRange (view, attrName, min, max));
EXPECT (min == minValue);
EXPECT (max == maxValue);
}
template <typename ViewClass, typename Proc>
void testAttribute (const IdStringPtr viewName, const std::string& attrName,
const IdStringPtr attrValue, IUIDescription* desc, const Proc& proc,
bool disableRememberAttributes = false)
{
UIViewFactory factory;
factory.disableRememberAttributes = disableRememberAttributes;
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, viewName);
a.setAttribute (attrName, attrValue);
auto v = owned (factory.createView (a, desc));
auto view = v.cast<ViewClass> ();
EXPECT (view);
EXPECT (proc (view));
UIAttributes a2;
factory.getAttributesForView (view, desc, a2);
auto str = a2.getAttributeValue (attrName);
EXPECT (str);
EXPECT (*str == attrValue);
}
template <typename ViewClass, typename Proc>
void testAttribute (const IdStringPtr viewName, const std::string& attrName, int32_t attrValue,
IUIDescription* desc, const Proc& proc)
{
UIViewFactory factory;
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, viewName);
a.setIntegerAttribute (attrName, attrValue);
auto v = owned (factory.createView (a, desc));
auto view = v.cast<ViewClass> ();
EXPECT (view);
EXPECT (proc (view));
UIAttributes a2;
factory.getAttributesForView (view, desc, a2);
int32_t value;
a2.getIntegerAttribute (attrName, value);
EXPECT (value == attrValue);
}
template <typename ViewClass, typename Proc>
void testAttribute (const IdStringPtr viewName, const std::string& attrName, bool attrValue,
IUIDescription* desc, const Proc& proc)
{
UIViewFactory factory;
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, viewName);
a.setBooleanAttribute (attrName, attrValue);
auto v = owned (factory.createView (a, desc));
auto view = v.cast<ViewClass> ();
EXPECT (view);
EXPECT (proc (view));
UIAttributes a2;
factory.getAttributesForView (view, desc, a2);
bool value;
a2.getBooleanAttribute (attrName, value);
EXPECT (value == attrValue);
}
template <typename ViewClass, typename Proc>
void testAttribute (const IdStringPtr viewName, const std::string& attrName, double attrValue,
IUIDescription* desc, const Proc& proc)
{
UIViewFactory factory;
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, viewName);
a.setDoubleAttribute (attrName, attrValue);
auto v = owned (factory.createView (a, desc));
auto view = v.cast<ViewClass> ();
EXPECT (view);
EXPECT (proc (view));
UIAttributes a2;
factory.getAttributesForView (view, desc, a2);
double value;
a2.getDoubleAttribute (attrName, value);
EXPECT (value == attrValue);
}
template <typename ViewClass, typename Proc>
void testAttribute (const IdStringPtr viewName, const std::string& attrName, const CRect& attrValue,
IUIDescription* desc, const Proc& proc)
{
UIViewFactory factory;
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, viewName);
a.setRectAttribute (attrName, attrValue);
auto v = owned (factory.createView (a, desc));
auto view = v.cast<ViewClass> ();
EXPECT (view);
EXPECT (proc (view));
UIAttributes a2;
factory.getAttributesForView (view, desc, a2);
CRect value;
a2.getRectAttribute (attrName, value);
EXPECT (value == attrValue);
}
template <typename ViewClass, typename Proc>
void testAttribute (const IdStringPtr viewName, const std::string& attrName,
const CPoint& attrValue, IUIDescription* desc, const Proc& proc)
{
UIViewFactory factory;
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, viewName);
a.setPointAttribute (attrName, attrValue);
auto v = owned (factory.createView (a, desc));
auto view = v.cast<ViewClass> ();
EXPECT (view);
EXPECT (proc (view));
UIAttributes a2;
factory.getAttributesForView (view, desc, a2);
CPoint value;
a2.getPointAttribute (attrName, value);
EXPECT (value == attrValue);
}
inline bool operator!= (const CGradient& g1, const CGradient& g2)
{
auto cs1 = g1.getColorStops ();
auto cs2 = g2.getColorStops ();
return cs1 != cs2;
}
inline bool operator== (const CGradient& g1, const CGradient& g2)
{
auto cs1 = g1.getColorStops ();
auto cs2 = g2.getColorStops ();
return cs1 == cs2;
}
} // VSTGUI
@@ -0,0 +1,137 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/controls/cstringlist.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
//------------------------------------------------------------------------
static StringListControlDrawer* getDrawer (CListControl* c)
{
return dynamic_cast<StringListControlDrawer*> (c->getDrawer ());
}
//------------------------------------------------------------------------
static StaticListControlConfigurator* getConfigurator (CListControl* c)
{
return dynamic_cast<StaticListControlConfigurator*> (c->getConfigurator ());
}
//------------------------------------------------------------------------
TEST_CASE (StringListControlCreatorTest, StyleHover)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrStyleHover, true, &uidesc, [&] (CListControl* v) {
return (getConfigurator (v)->getFlags () & CListControlRowDesc::Hoverable) != 0;
});
testAttribute<CListControl> (
kCStringListControl, kAttrStyleHover, false, &uidesc, [&] (CListControl* v) {
return (getConfigurator (v)->getFlags () & CListControlRowDesc::Hoverable) == 0;
});
}
TEST_CASE (StringListControlCreatorTest, RowHeight)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrRowHeight, 14., &uidesc,
[&] (CListControl* v) { return getConfigurator (v)->getRowHeight () == 14.; });
}
TEST_CASE (StringListControlCreatorTest, Font)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrFont, kFontName, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getFont () == uidesc.font; }, true);
}
TEST_CASE (StringListControlCreatorTest, TextAlignment)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrTextAlignment, strRight, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getTextAlign () == kRightText; });
testAttribute<CListControl> (
kCStringListControl, kAttrTextAlignment, strLeft, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getTextAlign () == kLeftText; });
testAttribute<CListControl> (
kCStringListControl, kAttrTextAlignment, strCenter, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getTextAlign () == kCenterText; });
}
TEST_CASE (StringListControlCreatorTest, FontColor)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrFontColor, kColorName, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getFontColor () == uidesc.color; });
}
TEST_CASE (StringListControlCreatorTest, SelectedFontColor)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrSelectedFontColor, kColorName, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getSelectedFontColor () == uidesc.color; });
}
TEST_CASE (StringListControlCreatorTest, BackColor)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrBackColor, kColorName, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getBackColor () == uidesc.color; });
}
TEST_CASE (StringListControlCreatorTest, SelectedBackColor)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrSelectedBackColor, kColorName, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getSelectedBackColor () == uidesc.color; });
}
TEST_CASE (StringListControlCreatorTest, HoverColor)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrHoverColor, kColorName, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getHoverColor () == uidesc.color; });
}
TEST_CASE (StringListControlCreatorTest, LineColor)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrLineColor, kColorName, &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getLineColor () == uidesc.color; });
}
TEST_CASE (StringListControlCreatorTest, LineWidth)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrLineWidth, 14., &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getLineWidth () == 14.; });
}
TEST_CASE (StringListControlCreatorTest, TextInset)
{
DummyUIDescription uidesc;
testAttribute<CListControl> (
kCStringListControl, kAttrTextInset, 14., &uidesc,
[&] (CListControl* v) { return getDrawer (v)->getTextInset () == 14.; });
}
} // VSTGUI
@@ -0,0 +1,55 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/cbitmap.h"
#include "../../../../lib/ccolor.h"
#include "../../../../lib/cpoint.h"
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/uiviewcreator.h"
#include "../../unittests.h"
#include "../uidescriptionadapter.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (UIViewCreatorTest, BitmapToString)
{
UIDescriptionAdapter uidesc;
std::string str;
CBitmap bitmap (CResourceDescription ("test.png"));
EXPECT (bitmapToString (&bitmap, str, &uidesc) == true);
EXPECT (str == "test.png");
CBitmap bitmap2 (CResourceDescription (100));
EXPECT (bitmapToString (&bitmap2, str, &uidesc) == true);
EXPECT (str == "100");
}
TEST_CASE (UIViewCreatorTest, ColorToString)
{
UIDescriptionAdapter uidesc;
std::string str;
CColor c (0, 0, 0, 255);
EXPECT (colorToString (c, str, &uidesc) == true);
EXPECT (str == "#000000ff")
c = CColor (0, 0, 255, 0);
EXPECT (colorToString (c, str, &uidesc) == true);
EXPECT (str == "#0000ff00")
c = CColor (0, 255, 0, 0);
EXPECT (colorToString (c, str, &uidesc) == true);
EXPECT (str == "#00ff0000")
c = CColor (255, 0, 0, 0);
EXPECT (colorToString (c, str, &uidesc) == true);
EXPECT (str == "#ff000000")
}
TEST_CASE (UIViewCreatorTest, EmptyStringToTransparentColor)
{
UIDescriptionAdapter uidesc;
std::string str = "";
CColor c;
EXPECT (stringToColor (&str, c, &uidesc) == true);
EXPECT (c == kTransparentCColor);
}
} // VSTGUI
@@ -0,0 +1,118 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../../lib/cstring.h"
#include "../../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../../uidescription/uiattributes.h"
#include "../../../../uidescription/uiviewfactory.h"
#include "../../../../uidescription/uiviewswitchcontainer.h"
#include "../../unittests.h"
#include "helpers.h"
namespace VSTGUI {
using namespace UIViewCreator;
TEST_CASE (UIViewSwitchContainerCreatorTest, TemplateNames)
{
DummyUIDescription uidesc;
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrTemplateNames, "temp1,temp2",
&uidesc, [] (UIViewSwitchContainer* v) {
auto controller =
dynamic_cast<UIDescriptionViewSwitchController*> (
v->getController ());
EXPECT (controller);
std::string str;
controller->getTemplateNames (str);
return str == "temp1,temp2";
});
}
TEST_CASE (UIViewSwitchContainerCreatorTest, TemplateSwitchControl)
{
DummyUIDescription uidesc;
uidesc.tag = 12345;
testAttribute<UIViewSwitchContainer> (
kUIViewSwitchContainer, kAttrTemplateSwitchControl, kTagName, &uidesc,
[&] (UIViewSwitchContainer* v) {
auto controller =
dynamic_cast<UIDescriptionViewSwitchController*> (v->getController ());
EXPECT (controller);
return controller->getSwitchControlTag () == uidesc.tag;
},
true);
}
TEST_CASE (UIViewSwitchContainerCreatorTest, AnimationStyle)
{
DummyUIDescription uidesc;
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrAnimationStyle, "fade",
&uidesc, [] (UIViewSwitchContainer* v) {
return v->getAnimationStyle () ==
UIViewSwitchContainer::kFadeInOut;
});
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrAnimationStyle, "move",
&uidesc, [] (UIViewSwitchContainer* v) {
return v->getAnimationStyle () ==
UIViewSwitchContainer::kMoveInOut;
});
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrAnimationStyle, "push",
&uidesc, [] (UIViewSwitchContainer* v) {
return v->getAnimationStyle () ==
UIViewSwitchContainer::kPushInOut;
});
}
TEST_CASE (UIViewSwitchContainerCreatorTest, AnimationTime)
{
DummyUIDescription uidesc;
testAttribute<UIViewSwitchContainer> (
kUIViewSwitchContainer, kAttrAnimationTime, 1234, &uidesc,
[] (UIViewSwitchContainer* v) { return v->getAnimationTime () == 1234; });
}
TEST_CASE (UIViewSwitchContainerCreatorTest, AnimationStyleValues)
{
DummyUIDescription uidesc;
testPossibleValues (kUIViewSwitchContainer, kAttrAnimationStyle, &uidesc,
{"fade", "move", "push"});
}
TEST_CASE (UIViewSwitchContainerCreatorTest, AnimationTimingFunction)
{
DummyUIDescription uidesc;
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrAnimationTimingFunction,
"linear", &uidesc, [] (UIViewSwitchContainer* v) {
return v->getTimingFunction () ==
UIViewSwitchContainer::kLinear;
});
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrAnimationTimingFunction,
"easy-in", &uidesc, [] (UIViewSwitchContainer* v) {
return v->getTimingFunction () ==
UIViewSwitchContainer::kEasyIn;
});
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrAnimationTimingFunction,
"easy-out", &uidesc, [] (UIViewSwitchContainer* v) {
return v->getTimingFunction () ==
UIViewSwitchContainer::kEasyOut;
});
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrAnimationTimingFunction,
"easy-in-out", &uidesc, [] (UIViewSwitchContainer* v) {
return v->getTimingFunction () ==
UIViewSwitchContainer::kEasyInOut;
});
testAttribute<UIViewSwitchContainer> (kUIViewSwitchContainer, kAttrAnimationTimingFunction,
"easy", &uidesc, [] (UIViewSwitchContainer* v) {
return v->getTimingFunction () ==
UIViewSwitchContainer::kEasy;
});
}
TEST_CASE (UIViewSwitchContainerCreatorTest, AnimationTimingFunctionValues)
{
DummyUIDescription uidesc;
testPossibleValues (kUIViewSwitchContainer, kAttrAnimationTimingFunction, &uidesc,
{"linear", "easy-in", "easy-out", "easy-in-out", "easy"});
}
} // VSTGUI
@@ -0,0 +1,351 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../lib/cview.h"
#include "../../../lib/cviewcontainer.h"
#include "../../../uidescription/detail/uiviewcreatorattributes.h"
#include "../../../uidescription/uiattributes.h"
#include "../../../uidescription/uiviewfactory.h"
#include "../unittests.h"
#include <algorithm>
namespace VSTGUI {
namespace {
class BaseView : public CView
{
public:
BaseView () : CView (CRect (0, 0, 0, 0)) {}
enum class State
{
kState1,
kState2,
kState3
};
State baseState {State::kState1};
};
class View : public BaseView
{
public:
View () {}
int32_t value {0};
};
class CustomView : public View
{
public:
CustomView () {}
};
static std::string baseViewAttr ("BaseViewAttr");
struct BaseViewCreator : public ViewCreatorAdapter
{
IdStringPtr getViewName () const override { return "BaseView"; }
UTF8StringPtr getDisplayName () const override { return "Base View"; }
IdStringPtr getBaseViewName () const override { return nullptr; }
CView* create (const UIAttributes& attributes, const IUIDescription* description) const override
{
return new BaseView ();
}
bool apply (CView* view, const UIAttributes& attributes,
const IUIDescription* description) const override
{
auto v = dynamic_cast<BaseView*> (view);
if (!v)
return false;
auto attr = attributes.getAttributeValue (baseViewAttr);
if (attr)
{
if (*attr == "1")
v->baseState = BaseView::State::kState1;
if (*attr == "2")
v->baseState = BaseView::State::kState2;
if (*attr == "3")
v->baseState = BaseView::State::kState3;
}
return true;
}
bool getAttributeNames (std::list<std::string>& attributeNames) const override
{
attributeNames.push_back (baseViewAttr);
return true;
}
AttrType getAttributeType (const std::string& attributeName) const override
{
if (attributeName == baseViewAttr)
return kListType;
return kUnknownType;
}
bool getAttributeValue (CView* view, const std::string& attributeName, std::string& stringValue,
const IUIDescription* desc) const override
{
auto v = dynamic_cast<BaseView*> (view);
if (!v)
return false;
if (attributeName == baseViewAttr)
{
switch (v->baseState)
{
case BaseView::State::kState1: stringValue = "1"; break;
case BaseView::State::kState2: stringValue = "2"; break;
case BaseView::State::kState3: stringValue = "3"; break;
}
return true;
}
return false;
}
bool getPossibleListValues (const std::string& attributeName,
std::list<const std::string*>& values) const override
{
if (attributeName != baseViewAttr)
return false;
static const std::string v1 = "1";
static const std::string v2 = "2";
static const std::string v3 = "3";
values.push_back (&v1);
values.push_back (&v2);
values.push_back (&v3);
return true;
}
bool getAttributeValueRange (const std::string& attributeName, double& minValue,
double& maxValue) const override
{
return false;
}
};
BaseViewCreator baseViewCreator;
static std::string viewAttr ("ViewAttr");
struct ViewCreator : public ViewCreatorAdapter
{
IdStringPtr getViewName () const override { return "TestView"; }
UTF8StringPtr getDisplayName () const override { return "Test View"; }
IdStringPtr getBaseViewName () const override { return "BaseView"; }
CView* create (const UIAttributes& attributes, const IUIDescription* description) const override
{
return new View ();
}
bool apply (CView* view, const UIAttributes& attributes,
const IUIDescription* description) const override
{
auto v = dynamic_cast<View*> (view);
if (!v)
return false;
int32_t value;
if (attributes.getIntegerAttribute (viewAttr, value))
v->value = value;
return true;
}
bool getAttributeNames (std::list<std::string>& attributeNames) const override
{
attributeNames.push_back (viewAttr);
return true;
}
AttrType getAttributeType (const std::string& attributeName) const override
{
if (attributeName == viewAttr)
return kTagType;
return kUnknownType;
}
bool getAttributeValue (CView* view, const std::string& attributeName, std::string& stringValue,
const IUIDescription* desc) const override
{
auto v = dynamic_cast<View*> (view);
if (!v)
return false;
if (attributeName == viewAttr)
{
stringValue = std::to_string (v->value);
return true;
}
return false;
}
bool getPossibleListValues (const std::string& attributeName,
std::list<const std::string*>& values) const override
{
return false;
}
bool getAttributeValueRange (const std::string& attributeName, double& minValue,
double& maxValue) const override
{
if (attributeName != viewAttr)
return false;
minValue = -10;
maxValue = 10;
return true;
}
};
ViewCreator viewCreator;
static SharedPointer<CView> createView (IViewFactory* factory)
{
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, viewCreator.getViewName ());
return owned (factory->createView (a, nullptr));
}
} // anonymous
TEST_SUITE_SETUP (UIViewFactoryTest)
{
auto factory = makeOwned<UIViewFactory> ();
factory->registerViewCreator (baseViewCreator);
factory->registerViewCreator (viewCreator);
TEST_SUITE_SET_STORAGE (SharedPointer<UIViewFactory>, factory);
}
TEST_SUITE_TEARDOWN (UIViewFactoryTest)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
factory->unregisterViewCreator (baseViewCreator);
factory->unregisterViewCreator (viewCreator);
factory = nullptr;
}
TEST_CASE (UIViewFactoryTest, RegisterViewCreator)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
UIViewFactory::StringPtrList registeredViews;
factory->collectRegisteredViewNames (registeredViews);
auto found =
std::find_if (registeredViews.begin (), registeredViews.end (),
[&] (const std::string*& str) { return *str == viewCreator.getViewName (); });
EXPECT (found != registeredViews.end ());
}
TEST_CASE (UIViewFactoryTest, CollectFilteredViewNames)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
UIViewFactory::StringPtrList registeredViews;
factory->collectRegisteredViewNames (registeredViews, "BaseView");
EXPECT (registeredViews.size () == 1);
}
TEST_CASE (UIViewFactoryTest, CollectRegisteredViewAndDisplayNames)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto list = factory->collectRegisteredViewAndDisplayNames ();
auto it = std::find_if (list.begin (), list.end (),
[] (const auto& value) { return *value.first == "BaseView"; });
EXPECT (it != list.end ());
EXPECT (UTF8StringView (it->second) == UTF8StringView ("Base View"));
}
TEST_CASE (UIViewFactoryTest, CreateView)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto v = createView (factory);
EXPECT (v != nullptr);
EXPECT (v.cast<View> () != nullptr);
}
TEST_CASE (UIViewFactoryTest, CreateUnknownView)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
UIAttributes a;
a.setAttribute (UIViewCreator::kAttrClass, "Unknown");
auto view = owned (factory->createView (a, nullptr));
EXPECT (view == nullptr);
}
TEST_CASE (UIViewFactoryTest, ApplyAttributes)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto v = createView (factory);
auto view = v.cast<View> ();
EXPECT (view->value == 0);
UIAttributes a;
a.setIntegerAttribute (viewAttr, 1);
factory->applyAttributeValues (v, a, nullptr);
EXPECT (view->value == 1);
}
TEST_CASE (UIViewFactoryTest, GetAttributeValue)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto v = createView (factory);
std::string value;
factory->getAttributeValue (v, viewAttr, value, nullptr);
EXPECT (value == "0");
}
TEST_CASE (UIViewFactoryTest, GetAttributeNames)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto v = createView (factory);
UIViewFactory::StringList attributeNames;
EXPECT (factory->getAttributeNamesForView (v, attributeNames) == true);
EXPECT (attributeNames.size () == 2);
EXPECT (attributeNames.front () == viewAttr);
}
TEST_CASE (UIViewFactoryTest, GetAttributesForView)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto v = createView (factory);
UIAttributes a;
factory->getAttributesForView (v, nullptr, a);
EXPECT (a.hasAttribute (viewAttr) == true);
EXPECT (a.hasAttribute (baseViewAttr) == true);
}
TEST_CASE (UIViewFactoryTest, GetPossibleListValues)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto v = createView (factory);
UIViewFactory::StringPtrList values;
EXPECT (factory->getPossibleAttributeListValues (v, baseViewAttr, values) == true);
EXPECT (values.size () == 3);
}
TEST_CASE (UIViewFactoryTest, GetAttributeValueRange)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto v = createView (factory);
double minValue;
double maxValue;
EXPECT (factory->getAttributeValueRange (v, viewAttr, minValue, maxValue) == true);
EXPECT (minValue == -10.);
EXPECT (maxValue == 10.);
EXPECT (factory->getAttributeValueRange (v, baseViewAttr, minValue, maxValue) == false);
}
TEST_CASE (UIViewFactoryTest, DefaultViewCreation)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
UIAttributes a;
auto v = owned (factory->createView (a, nullptr));
EXPECT (v.cast<CViewContainer> ());
}
TEST_CASE (UIViewFactoryTest, ApplyCustomViewAttributes)
{
auto& factory = TEST_SUITE_GET_STORAGE (SharedPointer<UIViewFactory>);
auto view = owned (new CustomView ());
UIAttributes a;
a.setAttribute (baseViewAttr, "3");
EXPECT (factory->applyCustomViewAttributeValues (view, "TestView", a, nullptr));
EXPECT (view->baseState == BaseView::State::kState3);
}
} // VSTGUI
@@ -0,0 +1,118 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../../../lib/controls/cbuttons.h"
#include "../../../lib/cstring.h"
#include "../../../uidescription/uiviewswitchcontainer.h"
#include "../unittests.h"
#include "uidescriptionadapter.h"
namespace VSTGUI {
struct View1 : public CView
{
View1 () : CView (CRect ()) {}
};
struct View2 : public CView
{
View2 () : CView (CRect ()) {}
};
struct View3 : public CView
{
View3 () : CView (CRect ()) { setAutosizeFlags (kAutosizeAll); }
};
struct TestUIDescription : public UIDescriptionAdapter
{
CView* createView (UTF8StringPtr name, IController* controller) const override
{
if (UTF8StringView (name) == "v1")
return new View1 ();
else if (UTF8StringView (name) == "v2")
return new View2 ();
else if (UTF8StringView (name) == "v3")
return new View3 ();
return nullptr;
}
};
TEST_CASE (UIDescriptionViewSwitchControllerTest, SwitchViaIndex)
{
TestUIDescription uiDesc;
auto rootView = owned (new CViewContainer (CRect (0, 0, 100, 100)));
auto container = owned (new CViewContainer (CRect (0, 0, 100, 100)));
auto viewSwitch = new UIViewSwitchContainer (CRect (0, 0, 100, 100));
viewSwitch->setAnimationTime (0);
auto controller = new UIDescriptionViewSwitchController (viewSwitch, &uiDesc, nullptr);
controller->setTemplateNames ("v1,v2");
EXPECT (container->addView (viewSwitch));
container->attached (rootView);
EXPECT (viewSwitch->getView (0) == nullptr);
viewSwitch->setCurrentViewIndex (0);
EXPECT (dynamic_cast<View1*> (viewSwitch->getView (0)));
viewSwitch->setCurrentViewIndex (1);
EXPECT (dynamic_cast<View2*> (viewSwitch->getView (0)));
container->removed (rootView);
}
TEST_CASE (UIDescriptionViewSwitchControllerTest, SwitchViaControl)
{
TestUIDescription uiDesc;
auto rootView = owned (new CViewContainer (CRect (0, 0, 100, 100)));
auto container = owned (new CViewContainer (CRect (0, 0, 100, 100)));
auto viewSwitch = new UIViewSwitchContainer (CRect (0, 0, 100, 100));
viewSwitch->setAnimationTime (0);
auto control = new COnOffButton (CRect (0, 0, 0, 0));
control->setTag (1);
auto controller = new UIDescriptionViewSwitchController (viewSwitch, &uiDesc, nullptr);
controller->setTemplateNames ("v1,v2");
controller->setSwitchControlTag (1);
EXPECT (container->addView (control));
EXPECT (container->addView (viewSwitch));
container->attached (rootView);
EXPECT (dynamic_cast<View1*> (viewSwitch->getView (0)));
control->setValue (1.f);
control->valueChanged ();
EXPECT (dynamic_cast<View2*> (viewSwitch->getView (0)));
container->removed (rootView);
}
TEST_CASE (UIDescriptionViewSwitchControllerTest, AutosizeAll)
{
TestUIDescription uiDesc;
auto rootView = owned (new CViewContainer (CRect (0, 0, 100, 100)));
auto container = owned (new CViewContainer (CRect (0, 0, 100, 100)));
auto viewSwitch = new UIViewSwitchContainer (CRect (0, 0, 100, 100));
auto controller = new UIDescriptionViewSwitchController (viewSwitch, &uiDesc, nullptr);
controller->setTemplateNames ("v3");
EXPECT (container->addView (viewSwitch));
container->attached (rootView);
EXPECT (viewSwitch->getView (0) == nullptr);
viewSwitch->setCurrentViewIndex (0);
auto view = viewSwitch->getView (0);
EXPECT (dynamic_cast<View3*> (view));
EXPECT (view->getViewSize () == container->getViewSize ());
container->removed (rootView);
}
TEST_CASE (UIDescriptionViewSwitchControllerTest, NoAnimation)
{
TestUIDescription uiDesc;
auto rootView = owned (new CViewContainer (CRect (0, 0, 100, 100)));
auto container = owned (new CViewContainer (CRect (0, 0, 100, 100)));
auto viewSwitch = new UIViewSwitchContainer (CRect (0, 0, 100, 100));
viewSwitch->setAnimationTime (0);
auto controller = new UIDescriptionViewSwitchController (viewSwitch, &uiDesc, nullptr);
controller->setTemplateNames ("v1");
EXPECT (container->addView (viewSwitch));
container->attached (rootView);
EXPECT (viewSwitch->getView (0) == nullptr);
viewSwitch->setCurrentViewIndex (0);
EXPECT (dynamic_cast<View1*> (viewSwitch->getView (0)));
container->removed (rootView);
}
} // VSTGUI
@@ -0,0 +1,95 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
#include "../unittests.h"
#if VSTGUI_ENABLE_XML_PARSER
#include "../../../uidescription/uicontentprovider.h"
#include "../../../uidescription/xmlparser.h"
#include <string>
namespace VSTGUI {
using namespace Xml;
namespace {
struct Handler : public IHandler
{
bool stopOnStartElement {false};
void startXmlElement (Parser* parser, IdStringPtr elementName,
UTF8StringPtr* elementAttributes) override
{
if (stopOnStartElement)
parser->stop ();
}
void endXmlElement (Parser* parser, IdStringPtr name) override {}
void xmlCharData (Parser* parser, const int8_t* data, int32_t length) override {}
void xmlComment (Parser* parser, IdStringPtr comment) override {}
};
} // anonymous
constexpr auto validXML =
R"(<?xml version="1.0" encoding="UTF-8"?>
<tag attr="bla">
CHARDATA
<!-- comment -->
</tag>
)";
constexpr auto validXMLWithJunkAtEnd =
R"(<?xml version="1.0" encoding="UTF-8"?>
<tag attr="bla">
CHARDATA
<!-- comment -->
</tag>
this is junk
)";
constexpr auto invalidXML =
R"(
<tag attr="bla">
CHARDATA
<!-- comment -->
</tag2>
)";
TEST_CASE (XMLParserTest, ValidParse)
{
MemoryContentProvider provider (validXML, static_cast<uint32_t> (strlen (validXML)));
Handler handler;
Parser p;
EXPECT (p.parse (&provider, &handler) == true);
}
TEST_CASE (XMLParserTest, ValidParseWithJunkAtEnd)
{
MemoryContentProvider provider (validXMLWithJunkAtEnd,
static_cast<uint32_t> (strlen (validXMLWithJunkAtEnd)));
Handler handler;
Parser p;
EXPECT (p.parse (&provider, &handler) == true);
}
TEST_CASE (XMLParserTest, InvalidParse)
{
MemoryContentProvider provider (invalidXML, static_cast<uint32_t> (strlen (invalidXML)));
Handler handler;
Parser p;
EXPECT (p.parse (&provider, &handler) == false);
}
TEST_CASE (XMLParserTest, StopParse)
{
MemoryContentProvider provider (validXML, static_cast<uint32_t> (strlen (validXML)));
Handler handler;
handler.stopOnStartElement = true;
Parser p;
EXPECT (p.parse (&provider, &handler) == false);
}
} // VSTGUI
#endif // VSTGUI_ENABLE_XML_PARSER