Initial release
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
add_subdirectory(unittest)
|
||||
add_subdirectory(uidescriptioneditorapp)
|
||||
add_subdirectory(gridlayouttestapp)
|
||||
@@ -0,0 +1,22 @@
|
||||
##########################################################################################
|
||||
# VSTGUI base64codecspeed
|
||||
##########################################################################################
|
||||
set(target base64codecspeed)
|
||||
|
||||
set(${target}_sources
|
||||
"main.cpp"
|
||||
"../../lib/vstguidebug.cpp"
|
||||
)
|
||||
|
||||
##########################################################################################
|
||||
include_directories(../../../)
|
||||
add_executable(${target}
|
||||
${${target}_sources}
|
||||
)
|
||||
target_link_libraries(${target}
|
||||
${${target}_PLATFORM_LIBS}
|
||||
)
|
||||
|
||||
vstgui_set_cxx_version(${target} ${VSTGUI_CXX_VERSION})
|
||||
set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} FOLDER Tests)
|
||||
target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS})
|
||||
@@ -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 "vstgui/uidescription/base64codec.h"
|
||||
#include "vstgui/lib/malloc.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
using namespace VSTGUI;
|
||||
|
||||
int main ()
|
||||
{
|
||||
Buffer<uint8_t> origData;
|
||||
origData.allocate (1024*1024*500);
|
||||
|
||||
std::independent_bits_engine<std::default_random_engine, sizeof (uint16_t) * 8, uint16_t> rbe;
|
||||
std::generate (origData.get (), origData.get () + origData.size (), std::ref (rbe));
|
||||
|
||||
auto encoderResult = Base64Codec::encode (origData.get (), origData.size ());
|
||||
auto decoderResult = Base64Codec::decode (encoderResult.data.get (), encoderResult.dataSize);
|
||||
|
||||
if (origData.size () != decoderResult.dataSize)
|
||||
return -1;
|
||||
|
||||
if (memcmp (origData.get (), decoderResult.data.get (), origData.size ()) != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
##########################################################################################
|
||||
# VSTGUI GFXTest Application
|
||||
##########################################################################################
|
||||
set(target GFXTest)
|
||||
|
||||
set(${target}_sources
|
||||
"source/app.cpp"
|
||||
"source/drawdevicetests.cpp"
|
||||
"source/drawdevicetests.h"
|
||||
)
|
||||
|
||||
set(${target}_resources
|
||||
"resource/Window.uidesc"
|
||||
"resource/DrawDeviceTests.uidesc"
|
||||
)
|
||||
|
||||
vstgui_add_executable(${target} "${${target}_sources}")
|
||||
vstgui_add_resources(${target} "${${target}_resources}")
|
||||
vstgui_set_target_bundle_id(${target} "vstgui.tests.gfxtest")
|
||||
vstgui_set_target_infoplist(${target} "resource/Info.plist")
|
||||
vstgui_set_target_rcfile(${target} "resource/gfxtest.rc")
|
||||
vstgui_set_cxx_version(${target} ${VSTGUI_CXX_VERSION})
|
||||
target_include_directories(${target} PRIVATE ../../../)
|
||||
set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} FOLDER Tests)
|
||||
|
||||
+301
@@ -0,0 +1,301 @@
|
||||
{
|
||||
"vstgui-ui-description": {
|
||||
"version": "1",
|
||||
"variables": {},
|
||||
"bitmaps": {},
|
||||
"fonts": {},
|
||||
"colors": {
|
||||
"background": "#c6c6c6ff",
|
||||
"halfwhite": "#ffffff94"
|
||||
},
|
||||
"gradients": {
|
||||
"Default TextButton Gradient": [
|
||||
{
|
||||
"rgba": "#dcdcdcff",
|
||||
"start": "0"
|
||||
},
|
||||
{
|
||||
"rgba": "#b4b4b4ff",
|
||||
"start": "1"
|
||||
}
|
||||
],
|
||||
"Default TextButton Gradient Highlighted": [
|
||||
{
|
||||
"rgba": "#b4b4b4ff",
|
||||
"start": "0"
|
||||
},
|
||||
{
|
||||
"rgba": "#646464ff",
|
||||
"start": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"control-tags": {
|
||||
"ViewSelector": "0"
|
||||
},
|
||||
"custom": {
|
||||
"UIGridController": {
|
||||
"Grids": "1x 1,5x 5,10x 10,12x 12,15x 15",
|
||||
"Size": "10, 10"
|
||||
},
|
||||
"UITemplateController": {
|
||||
"SelectedTemplate": "Window"
|
||||
},
|
||||
"UIEditController": {
|
||||
"EditViewScale": "1",
|
||||
"EditorSize": "0, 0, 673, 618",
|
||||
"SplitViewSize_0_0": "0.7820945945945946276012250564235728234053",
|
||||
"SplitViewSize_0_1": "0.1841216216216216283729778524502762593329",
|
||||
"SplitViewSize_1_0": "0.4966216216216216006174022368213627487421",
|
||||
"SplitViewSize_1_1": "0.4966216216216216006174022368213627487421",
|
||||
"SplitViewSize_2_0": "0.6196136701337295882296984927961602807045",
|
||||
"SplitViewSize_2_1": "0.3729569093610698438112649455433711409569",
|
||||
"TabSwitchValue": "1",
|
||||
"Version": "1"
|
||||
},
|
||||
"UIAttributesController": {},
|
||||
"UIViewCreatorDataSource": {
|
||||
"SelectedRow": "28"
|
||||
},
|
||||
"UIGradientsDataSource": {
|
||||
"SelectedRow": "-1"
|
||||
},
|
||||
"UIBitmapsDataSource": {
|
||||
"SelectedRow": "-1"
|
||||
},
|
||||
"UIColorsDataSource": {
|
||||
"SelectedRow": "0"
|
||||
},
|
||||
"UITagsDataSource": {
|
||||
"SelectedRow": "-1"
|
||||
},
|
||||
"UIDescFilePath": {
|
||||
"path": "/Users/scheffle/Source/vstgui/vstgui/tests/gfxtest/resource/DrawDeviceTests.uidesc"
|
||||
}
|
||||
},
|
||||
"templates": {
|
||||
"Window": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "background",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "300, 300",
|
||||
"sub-controller": "ViewCreator",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CSegmentButton": {
|
||||
"attributes": {
|
||||
"autosize": "left right top ",
|
||||
"class": "CSegmentButton",
|
||||
"control-tag": "ViewSelector",
|
||||
"default-value": "0.5",
|
||||
"font": "~ NormalFont",
|
||||
"frame-color": "~ BlackCColor",
|
||||
"frame-width": "1",
|
||||
"gradient": "Default TextButton Gradient",
|
||||
"gradient-highlighted": "Default TextButton Gradient Highlighted",
|
||||
"icon-text-margin": "0",
|
||||
"max-value": "1",
|
||||
"min-value": "0",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "10, 10",
|
||||
"round-radius": "5",
|
||||
"segment-names": "Lines/Rects,BitmapFilter,InvalidRects",
|
||||
"selection-mode": "Single",
|
||||
"size": "280, 20",
|
||||
"style": "horizontal",
|
||||
"text-alignment": "center",
|
||||
"text-color": "~ BlackCColor",
|
||||
"text-color-highlighted": "~ WhiteCColor",
|
||||
"transparent": "false",
|
||||
"wants-focus": "true",
|
||||
"wheel-inc-value": "0.1"
|
||||
}
|
||||
},
|
||||
"UIViewSwitchContainer": {
|
||||
"attributes": {
|
||||
"animation-style": "fade",
|
||||
"animation-time": "80",
|
||||
"animation-timing-function": "linear",
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ BlackCColor",
|
||||
"background-color-draw-style": "stroked",
|
||||
"class": "UIViewSwitchContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "10, 40",
|
||||
"size": "280, 250",
|
||||
"template-names": "Rects,BitmapFilter,InvalidRegion",
|
||||
"template-switch-control": "ViewSelector",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CScrollView": {
|
||||
"attributes": {
|
||||
"auto-drag-scrolling": "false",
|
||||
"auto-hide-scrollbars": "false",
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "halfwhite",
|
||||
"background-color-draw-style": "filled",
|
||||
"bordered": "true",
|
||||
"class": "CScrollView",
|
||||
"container-size": "500, 500",
|
||||
"follow-focus-view": "false",
|
||||
"horizontal-scrollbar": "true",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"overlay-scrollbars": "false",
|
||||
"scrollbar-background-color": "#ffffffc8",
|
||||
"scrollbar-frame-color": "~ BlackCColor",
|
||||
"scrollbar-scroller-color": "~ BlueCColor",
|
||||
"scrollbar-width": "16",
|
||||
"size": "280, 250",
|
||||
"template": "Rects",
|
||||
"transparent": "false",
|
||||
"vertical-scrollbar": "true",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Rects": {
|
||||
"attributes": {
|
||||
"auto-drag-scrolling": "false",
|
||||
"auto-hide-scrollbars": "false",
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "halfwhite",
|
||||
"background-color-draw-style": "filled",
|
||||
"bordered": "true",
|
||||
"class": "CScrollView",
|
||||
"container-size": "500, 500",
|
||||
"follow-focus-view": "false",
|
||||
"horizontal-scrollbar": "true",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"overlay-scrollbars": "false",
|
||||
"scrollbar-background-color": "#ffffffc8",
|
||||
"scrollbar-frame-color": "~ BlackCColor",
|
||||
"scrollbar-scroller-color": "~ BlueCColor",
|
||||
"scrollbar-width": "16",
|
||||
"size": "400, 400",
|
||||
"transparent": "false",
|
||||
"vertical-scrollbar": "true",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CView": {
|
||||
"attributes": {
|
||||
"class": "CView",
|
||||
"custom-view-name": "RectsView",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "500, 500",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"InvalidRegion": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ BlackCColor",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "true",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CView": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"class": "CView",
|
||||
"custom-view-name": "InvalidRegionView",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"BitmapFilter": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ BlackCColor",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "true",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CView": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"class": "CView",
|
||||
"custom-view-name": "BitmapsFilterView",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"BitmapFilter": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ BlackCColor",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "true",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CView": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"class": "CView",
|
||||
"custom-view-name": "BitmapsFilterView",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>GFXTest</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>GFXTest</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Arne Scheffler. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1 @@
|
||||
BNDL????
|
||||
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"vstgui-ui-description": {
|
||||
"version": "1",
|
||||
"variables": {},
|
||||
"bitmaps": {},
|
||||
"fonts": {},
|
||||
"colors": {},
|
||||
"gradients": {
|
||||
"Default TextButton Gradient": [
|
||||
{
|
||||
"rgba": "#dcdcdcff",
|
||||
"start": "0"
|
||||
},
|
||||
{
|
||||
"rgba": "#b4b4b4ff",
|
||||
"start": "1"
|
||||
}
|
||||
],
|
||||
"Default TextButton Gradient Highlighted": [
|
||||
{
|
||||
"rgba": "#b4b4b4ff",
|
||||
"start": "0"
|
||||
},
|
||||
{
|
||||
"rgba": "#646464ff",
|
||||
"start": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"control-tags": {
|
||||
"ShowDrawDeviceTests": "0"
|
||||
},
|
||||
"custom": {
|
||||
"UIDescFilePath": {
|
||||
"path": "/Users/scheffle/Source/vstgui/vstgui/tests/gfxtest/resource/Window.uidesc"
|
||||
},
|
||||
"UIGridController": {
|
||||
"Grids": "1x 1,5x 5,10x 10,12x 12,15x 15",
|
||||
"Size": "10, 10"
|
||||
},
|
||||
"UITemplateController": {
|
||||
"SelectedTemplate": "Window"
|
||||
},
|
||||
"UIEditController": {
|
||||
"EditViewScale": "1",
|
||||
"EditorSize": "0, 0, 500, 500",
|
||||
"SplitViewSize_0_0": "0.7278481012658227777833985783217940479517",
|
||||
"SplitViewSize_0_1": "0.2299578059071729907447689811306190676987",
|
||||
"SplitViewSize_1_0": "0.4662447257383966481292247863166267052293",
|
||||
"SplitViewSize_1_1": "0.523206751054852370330650046525988727808",
|
||||
"SplitViewSize_2_0": "0.6400000000000000133226762955018784850836",
|
||||
"SplitViewSize_2_1": "0.3499999999999999777955395074968691915274",
|
||||
"TabSwitchValue": "0",
|
||||
"Version": "1"
|
||||
},
|
||||
"UIAttributesController": {
|
||||
"UIAttributesController": "tag"
|
||||
},
|
||||
"UIViewCreatorDataSource": {
|
||||
"SelectedRow": "23"
|
||||
},
|
||||
"UITagsDataSource": {
|
||||
"SelectedRow": "-1"
|
||||
}
|
||||
},
|
||||
"templates": {
|
||||
"Window": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ GreyCColor",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "300, 300",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CTextButton": {
|
||||
"attributes": {
|
||||
"background-offset": "0, 0",
|
||||
"class": "CTextButton",
|
||||
"control-tag": "ShowDrawDeviceTests",
|
||||
"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": "false",
|
||||
"max-value": "1",
|
||||
"min-value": "0",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "10, 10",
|
||||
"round-radius": "6",
|
||||
"size": "190, 20",
|
||||
"text-alignment": "center",
|
||||
"text-color": "~ BlackCColor",
|
||||
"text-color-highlighted": "~ WhiteCColor",
|
||||
"title": "Show DrawDevice Tests",
|
||||
"transparent": "false",
|
||||
"wants-focus": "true",
|
||||
"wheel-inc-value": "0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,59 @@
|
||||
// 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 "drawdevicetests.h"
|
||||
#include "vstgui/standalone/include/helpers/appdelegate.h"
|
||||
#include "vstgui/standalone/include/helpers/uidesc/modelbinding.h"
|
||||
#include "vstgui/standalone/include/helpers/value.h"
|
||||
#include "vstgui/standalone/include/helpers/windowlistener.h"
|
||||
#include "vstgui/standalone/include/iapplication.h"
|
||||
#include "vstgui/standalone/include/iuidescwindow.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
namespace Standalone {
|
||||
|
||||
using namespace Application;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class GFXTestApp : public DelegateAdapter, public WindowListenerAdapter
|
||||
{
|
||||
public:
|
||||
GFXTestApp () : DelegateAdapter ({"gfxtest", "1.0.0", "vstgui.tests.gfxtest"}) {}
|
||||
|
||||
void finishLaunching () override
|
||||
{
|
||||
auto modelBinding = UIDesc::ModelBindingCallbacks::make ();
|
||||
modelBinding->addValue (Value::make ("ShowDrawDeviceTests"),
|
||||
UIDesc::ValueCalls::onAction ([] (auto& value) {
|
||||
makeDrawDeviceTestsWindow ();
|
||||
value.performEdit (0.);
|
||||
}));
|
||||
|
||||
UIDesc::Config config;
|
||||
config.uiDescFileName = "Window.uidesc";
|
||||
config.viewName = "Window";
|
||||
config.modelBinding = modelBinding;
|
||||
config.windowConfig.title = "GFXTests";
|
||||
config.windowConfig.autoSaveFrameName = "GFXTestsWindow";
|
||||
config.windowConfig.style.border ().close ().size ().centered ();
|
||||
if (auto window = UIDesc::makeWindow (config))
|
||||
{
|
||||
window->show ();
|
||||
window->registerWindowListener (this);
|
||||
}
|
||||
else
|
||||
{
|
||||
IApplication::instance ().quit ();
|
||||
}
|
||||
}
|
||||
|
||||
void onClosed (const IWindow& window) override { IApplication::instance ().quit (); }
|
||||
};
|
||||
|
||||
static Init gAppDelegate (std::make_unique<GFXTestApp> ());
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // Standalone
|
||||
} // VSTGUI
|
||||
+396
@@ -0,0 +1,396 @@
|
||||
// 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 "drawdevicetests.h"
|
||||
#include "vstgui/lib/cbitmap.h"
|
||||
#include "vstgui/lib/cbitmapfilter.h"
|
||||
#include "vstgui/lib/cfileselector.h"
|
||||
#include "vstgui/lib/cframe.h"
|
||||
#include "vstgui/lib/cgraphicstransform.h"
|
||||
#include "vstgui/lib/coffscreencontext.h"
|
||||
#include "vstgui/lib/platform/iplatformbitmap.h"
|
||||
#include "vstgui/lib/platform/platformfactory.h"
|
||||
#include "vstgui/standalone/include/helpers/menubuilder.h"
|
||||
#include "vstgui/standalone/include/helpers/uidesc/customization.h"
|
||||
#include "vstgui/standalone/include/helpers/uidesc/modelbinding.h"
|
||||
#include "vstgui/standalone/include/helpers/value.h"
|
||||
#include "vstgui/standalone/include/iapplication.h"
|
||||
#include "vstgui/standalone/include/iuidescwindow.h"
|
||||
#include "vstgui/uidescription/cstream.h"
|
||||
#include "vstgui/uidescription/delegationcontroller.h"
|
||||
#include "vstgui/uidescription/iuidescription.h"
|
||||
#include "vstgui/uidescription/uiattributes.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
namespace Standalone {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class CustomDrawView : public CView
|
||||
{
|
||||
public:
|
||||
using DrawFunction = std::function<void (CustomDrawView* view, CDrawContext& context, CPoint viewSize)>;
|
||||
|
||||
CustomDrawView (DrawFunction func) : CView (CRect (0, 0, 0, 0)), func (func) {}
|
||||
|
||||
void draw (CDrawContext* context) override
|
||||
{
|
||||
if (func)
|
||||
{
|
||||
CDrawContext::Transform t (
|
||||
*context, CGraphicsTransform ().translate (getViewSize ().getTopLeft ()));
|
||||
func (this, *context, getViewSize ().getSize ());
|
||||
}
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
if (func && buttons.isLeftButton ())
|
||||
{
|
||||
if (buttons.getModifierState () & kShift)
|
||||
saveAsPNG ();
|
||||
else
|
||||
invalid ();
|
||||
}
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string getSavePath ()
|
||||
{
|
||||
if (auto fs =
|
||||
owned (CNewFileSelector::create (getFrame (), CNewFileSelector::kSelectSaveFile)))
|
||||
{
|
||||
fs->setDefaultExtension (CFileExtension ("PNG", "png"));
|
||||
if (fs->runModal ())
|
||||
{
|
||||
return fs->getSelectedFile (0);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void saveAsPNG ()
|
||||
{
|
||||
auto filePath = getSavePath ();
|
||||
if (filePath.empty ())
|
||||
return;
|
||||
|
||||
auto size = getViewSize ().getSize ();
|
||||
auto scaleFactor = getFrame ()->getScaleFactor ();
|
||||
if (auto offscreen = COffscreenContext::create (size, scaleFactor))
|
||||
{
|
||||
offscreen->beginDraw ();
|
||||
func (this, *offscreen, size);
|
||||
offscreen->endDraw ();
|
||||
auto bitmap = offscreen->getBitmap ();
|
||||
if (auto platformBitmap = bitmap->getPlatformBitmap ())
|
||||
{
|
||||
auto buffer =
|
||||
getPlatformFactory ().createBitmapMemoryPNGRepresentation (platformBitmap);
|
||||
if (buffer.empty ())
|
||||
return;
|
||||
CFileStream stream;
|
||||
if (!stream.open (filePath.data (), CFileStream::kBinaryMode |
|
||||
CFileStream::kWriteMode |
|
||||
CFileStream::kTruncateMode))
|
||||
return;
|
||||
stream.writeRaw (buffer.data (), static_cast<uint32_t> (buffer.size ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DrawFunction func;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void drawRects (CDrawContext& context, CPoint size)
|
||||
{
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setFillColor (MakeCColor (0, 0, 0, 100));
|
||||
context.drawRect (CRect ().setSize (size), kDrawFilled);
|
||||
|
||||
//--
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setFrameColor (kBlackCColor);
|
||||
context.setLineStyle (kLineSolid);
|
||||
context.setLineWidth (1);
|
||||
context.drawRect (CRect (5, 5, 10, 10), kDrawStroked);
|
||||
context.setFrameColor (MakeCColor (0, 0, 0, 150));
|
||||
context.drawLine ({10, 5}, {25, 5});
|
||||
context.drawLine ({5, 10}, {5, 25});
|
||||
//--
|
||||
context.setDrawMode (kAliasing);
|
||||
auto hairline = context.getHairlineSize ();
|
||||
CRect r2 (40, 5, 50, 15);
|
||||
context.setLineWidth (5);
|
||||
context.setFrameColor (CColor (0, 0, 255, 100));
|
||||
context.drawRect (r2);
|
||||
context.setLineWidth (3);
|
||||
context.setFrameColor (CColor (255, 0, 0, 100));
|
||||
context.drawRect (r2);
|
||||
context.setLineWidth (1);
|
||||
context.setFrameColor (CColor (0, 255, 0, 100));
|
||||
context.drawRect (r2);
|
||||
//--
|
||||
r2 = {60, 5, 70, 15};
|
||||
context.setLineWidth (hairline);
|
||||
context.setFrameColor (CColor (0, 255, 0, 200));
|
||||
context.drawRect (r2);
|
||||
r2.inset (hairline, hairline);
|
||||
context.setFrameColor (CColor (255, 0, 0, 200));
|
||||
context.drawRect (r2);
|
||||
r2.inset (hairline, hairline);
|
||||
context.setFrameColor (CColor (0, 0, 255, 200));
|
||||
context.drawRect (r2);
|
||||
//--
|
||||
CRect r {5, 50, 0, 0};
|
||||
r.setSize ({20, 20});
|
||||
context.setLineWidth (1);
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setFillColor (MakeCColor (255, 0, 0, 255));
|
||||
context.drawRect (r, kDrawFilled);
|
||||
context.setFillColor (MakeCColor (0, 0, 0, 200));
|
||||
context.drawEllipse (r, kDrawFilled);
|
||||
context.setFrameColor (CColor (0, 255, 0, 100));
|
||||
context.drawRect (r, kDrawStroked);
|
||||
//--
|
||||
r = {50, 50, 80, 80};
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setLineWidth (1);
|
||||
context.setFrameColor (CColor (0, 255, 255, 100));
|
||||
context.drawLine (r.getTopLeft (), r.getTopRight ());
|
||||
context.drawLine (r.getBottomLeft (), r.getBottomRight ());
|
||||
r.inset (10, -10);
|
||||
context.drawLine (r.getTopRight (), r.getBottomRight ());
|
||||
context.drawLine (r.getTopLeft (), r.getBottomLeft ());
|
||||
r.left++;
|
||||
r.top += 11;
|
||||
r.bottom -= 10;
|
||||
context.setFillColor (CColor (255, 0, 0, 100));
|
||||
context.drawRect (r, kDrawFilled);
|
||||
//--
|
||||
r = {90, 90, 120, 120};
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setLineWidth (1);
|
||||
context.setFrameColor (CColor (0, 0, 255, 100));
|
||||
context.setFillColor (CColor (255, 0, 0, 100));
|
||||
context.drawEllipse (r, kDrawFilledAndStroked);
|
||||
r.offset (40, 0);
|
||||
context.setDrawMode (kAntiAliasing);
|
||||
context.drawEllipse (r, kDrawFilledAndStroked);
|
||||
//--
|
||||
r = {90, 130, 120, 160};
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setLineWidth (1);
|
||||
context.setFrameColor (CColor (0, 0, 255, 100));
|
||||
context.setFillColor (CColor (255, 0, 0, 100));
|
||||
context.drawEllipse (r, kDrawFilled);
|
||||
r2 = r;
|
||||
r2.extend (1, 1);
|
||||
context.drawEllipse (r2, kDrawStroked);
|
||||
r.offset (40, 0);
|
||||
context.setDrawMode (kAntiAliasing);
|
||||
context.drawEllipse (r, kDrawFilled);
|
||||
r2 = r;
|
||||
r2.extend (1, 1);
|
||||
context.drawEllipse (r2, kDrawStroked);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void drawBitmapFilter (CustomDrawView* view, CDrawContext& context, CPoint size)
|
||||
{
|
||||
auto boxBlurFilter = owned (BitmapFilter::Factory::getInstance ().createFilter (BitmapFilter::Standard::kBoxBlur));
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kRadius, 2);
|
||||
|
||||
auto offscreen = COffscreenContext::create ({20., 20.});
|
||||
offscreen->beginDraw ();
|
||||
offscreen->setFillColor (kRedCColor);
|
||||
offscreen->drawRect ({5, 5, 15, 15}, kDrawFilled);
|
||||
offscreen->endDraw ();
|
||||
auto bitmap = shared (offscreen->getBitmap ());
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kInputBitmap, bitmap.get ());
|
||||
boxBlurFilter->run (true);
|
||||
bitmap->draw (&context, {0, 0, 20, 20});
|
||||
|
||||
offscreen = COffscreenContext::create ({20., 20.});
|
||||
offscreen->beginDraw ();
|
||||
offscreen->clearRect({0, 0, 20, 20});
|
||||
offscreen->setFillColor (kGreenCColor);
|
||||
offscreen->drawRect ({5, 5, 15, 15}, kDrawFilled);
|
||||
offscreen->endDraw ();
|
||||
bitmap = shared (offscreen->getBitmap ());
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kInputBitmap, bitmap.get ());
|
||||
boxBlurFilter->run (true);
|
||||
bitmap->draw (&context, {20, 0, 40, 20});
|
||||
|
||||
offscreen = COffscreenContext::create ({20., 20.});
|
||||
offscreen->beginDraw ();
|
||||
offscreen->clearRect({0, 0, 20, 20});
|
||||
offscreen->setFillColor (kBlueCColor);
|
||||
offscreen->drawRect ({5, 5, 15, 15}, kDrawFilled);
|
||||
offscreen->endDraw ();
|
||||
bitmap = shared (offscreen->getBitmap ());
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kInputBitmap, bitmap.get ());
|
||||
boxBlurFilter->run (true);
|
||||
bitmap->draw (&context, {40, 0, 60, 20});
|
||||
|
||||
offscreen = COffscreenContext::create ({20., 20.});
|
||||
offscreen->beginDraw ();
|
||||
offscreen->clearRect({0, 0, 20, 20});
|
||||
offscreen->setFillColor (kGreyCColor);
|
||||
offscreen->drawRect ({5, 5, 15, 15}, kDrawFilled);
|
||||
offscreen->endDraw ();
|
||||
bitmap = shared (offscreen->getBitmap ());
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kInputBitmap, bitmap.get ());
|
||||
boxBlurFilter->run (true);
|
||||
bitmap->draw (&context, {60, 0, 80, 20});
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class InvalidateRegionTestView : public CView
|
||||
{
|
||||
public:
|
||||
InvalidateRegionTestView (const CRect& size) : CView (size) {}
|
||||
|
||||
void printRect (const char* prefix, const CRect& r)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugPrint ("%s, %d,%d (%dx%d)\n", prefix, static_cast<int32_t> (r.left),
|
||||
static_cast<int32_t> (r.top), static_cast<int32_t> (r.right - r.left),
|
||||
static_cast<int32_t> (r.bottom - r.top));
|
||||
#endif
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseDown (CPoint& where, const CButtonState& state) override
|
||||
{
|
||||
auto r1 = getViewSize ();
|
||||
r1.setWidth (r1.getWidth () / 2.);
|
||||
auto r2 = r1;
|
||||
r2.offset (r2.getWidth (), 0);
|
||||
|
||||
r2.inset (10, 50);
|
||||
r2.setHeight (r2.getHeight () / 2.);
|
||||
auto r3 = r2;
|
||||
r2.inset (0, 10);
|
||||
r3.offset (0, r3.getHeight ());
|
||||
r3.inset (0, 10);
|
||||
|
||||
r1.inset (10, 0);
|
||||
|
||||
invalRect (r1);
|
||||
invalRect (r2);
|
||||
invalRect (r3);
|
||||
return kMouseDownEventHandledButDontNeedMovedOrUpEvents;
|
||||
}
|
||||
|
||||
void invalRect (const CRect& r)
|
||||
{
|
||||
printRect ("InvalidRect: ", r);
|
||||
invalidRect (r);
|
||||
}
|
||||
|
||||
void drawRect (CDrawContext* context, const CRect& r) override
|
||||
{
|
||||
if (r == getViewSize ())
|
||||
{
|
||||
context->setFillColor (kWhiteCColor);
|
||||
context->drawRect (r, kDrawFilled);
|
||||
}
|
||||
else
|
||||
{
|
||||
printRect ("DrawRect: ", r);
|
||||
|
||||
double h, s, v;
|
||||
color.toHSV (h, s, v);
|
||||
h += 40;
|
||||
color.fromHSV (h, s, v);
|
||||
context->setFillColor (color);
|
||||
context->drawRect (r, kDrawFilled);
|
||||
}
|
||||
setDirty (false);
|
||||
}
|
||||
bool toggle {false};
|
||||
CColor color {kRedCColor};
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class ViewCreator : public DelegationController
|
||||
{
|
||||
public:
|
||||
ViewCreator (IController* parent) : DelegationController (parent) {}
|
||||
|
||||
CView* createView (const UIAttributes& attributes, const IUIDescription* description) override
|
||||
{
|
||||
if (auto customViewName = attributes.getAttributeValue (IUIDescription::kCustomViewName))
|
||||
{
|
||||
if (*customViewName == "RectsView")
|
||||
{
|
||||
return new CustomDrawView ([] (auto view, auto& ctx, auto size) { drawRects (ctx, size); });
|
||||
}
|
||||
if (*customViewName == "BitmapsFilterView")
|
||||
{
|
||||
return new CustomDrawView (
|
||||
[] (auto view, auto& ctx, auto size) { drawBitmapFilter (view, ctx, size); });
|
||||
}
|
||||
else if (*customViewName == "InvalidRegionView")
|
||||
{
|
||||
return new InvalidateRegionTestView (CRect (0, 0, 500, 500));
|
||||
}
|
||||
}
|
||||
return DelegationController::createView (attributes, description);
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class DrawDeviceTestsCustomization : public UIDesc::Customization, public NoMenuBuilder
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void makeDrawDeviceTestsWindow ()
|
||||
{
|
||||
static UTF8String windowTitle = "DrawDeviceTests";
|
||||
const auto& windows = IApplication::instance ().getWindows ();
|
||||
for (auto& window : windows)
|
||||
{
|
||||
if (window->getTitle () == windowTitle)
|
||||
{
|
||||
window->activate ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto modelBinding = UIDesc::ModelBindingCallbacks::make ();
|
||||
modelBinding->addValue (Value::makeStringListValue (
|
||||
"ViewSelector", {"Lines/Rects", "BitmapFilter", "InvalidRects"}));
|
||||
|
||||
auto drawDeviceTestsCustomization = std::make_shared<DrawDeviceTestsCustomization> ();
|
||||
drawDeviceTestsCustomization->addCreateViewControllerFunc (
|
||||
"ViewCreator",
|
||||
[] (const auto& name, auto parent, const auto uiDesc) { return new ViewCreator (parent); });
|
||||
|
||||
UIDesc::Config config;
|
||||
config.uiDescFileName = "DrawDeviceTests.uidesc";
|
||||
config.viewName = "Window";
|
||||
config.customization = drawDeviceTestsCustomization;
|
||||
config.modelBinding = modelBinding;
|
||||
config.windowConfig.title = windowTitle;
|
||||
config.windowConfig.autoSaveFrameName = "DrawDeviceTestsWindow";
|
||||
config.windowConfig.style.border ().close ().size ().centered ();
|
||||
if (auto window = UIDesc::makeWindow (config))
|
||||
window->show ();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // Standalone
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
namespace Standalone {
|
||||
|
||||
void makeDrawDeviceTestsWindow ();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // Standalone
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,29 @@
|
||||
##########################################################################################
|
||||
# VSTGUI Grid Layout Test App
|
||||
##########################################################################################
|
||||
option(VSTGUI_GRIDLAYOUTTESTAPP "Grid Layout Test App" OFF)
|
||||
|
||||
if(NOT VSTGUI_GRIDLAYOUTTESTAPP)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(target gridlayouttestapp)
|
||||
|
||||
set(${target}_sources
|
||||
"source/app.cpp"
|
||||
)
|
||||
|
||||
set(${target}_resources
|
||||
"resource/Window.uidesc"
|
||||
)
|
||||
|
||||
##########################################################################################
|
||||
vstgui_add_executable(${target} "${${target}_sources}" )
|
||||
vstgui_add_resources(${target} "${${target}_resources}")
|
||||
vstgui_set_target_bundle_id(${target} "vstgui.examples.gridlayouttestapp")
|
||||
vstgui_set_target_infoplist(${target} "resource/Info.plist")
|
||||
vstgui_set_target_rcfile(${target} "resource/windows.rc")
|
||||
vstgui_set_cxx_version(${target} 17)
|
||||
target_include_directories(${target} PRIVATE ../../../)
|
||||
set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} FOLDER Tests)
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2025 Arne Scheffler. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1 @@
|
||||
BNDL????
|
||||
+1202
File diff suppressed because it is too large
Load Diff
+1
@@ -0,0 +1 @@
|
||||
|
||||
+1021
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
cmake_minimum_required(VERSION 3.25.0)
|
||||
|
||||
project(vstgui_ios_test)
|
||||
|
||||
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
|
||||
message(FATAL_ERROR "Unsupported system (${CMAKE_SYSTEM_NAME}). Use -DCMAKE_SYSTEM_NAME=iOS when invoking cmake")
|
||||
endif()
|
||||
|
||||
set(target "iostest")
|
||||
set(sources
|
||||
"../../vstgui_ios.mm"
|
||||
"../../vstgui_uidescription.cpp"
|
||||
"iOS Standalone/AppDelegate.h"
|
||||
"iOS Standalone/AppDelegate.mm"
|
||||
"iOS Standalone/main.m"
|
||||
"iOS Standalone/ViewController.h"
|
||||
"iOS Standalone/ViewController.mm"
|
||||
)
|
||||
|
||||
set(resources
|
||||
"iOS Standalone/ios_test.uidesc"
|
||||
)
|
||||
|
||||
add_executable(${target} ${sources})
|
||||
set_source_files_properties(${resources} PROPERTIES
|
||||
MACOSX_PACKAGE_LOCATION "Resources"
|
||||
)
|
||||
target_sources(${target} PRIVATE ${resources})
|
||||
target_sources(${target} PRIVATE ${resources})
|
||||
target_include_directories(${target} PRIVATE "../../../")
|
||||
target_compile_features(${target} PUBLIC cxx_std_17)
|
||||
|
||||
target_link_libraries(${target}
|
||||
"-framework UIKit"
|
||||
"-framework QuartzCore"
|
||||
"-framework CoreGraphics"
|
||||
"-framework CoreText"
|
||||
"-framework ImageIO"
|
||||
"-framework MobileCoreServices"
|
||||
"-framework Accelerate"
|
||||
)
|
||||
|
||||
set(bundleID net.sourceforge.vstgui.iostest)
|
||||
|
||||
set_target_properties(${target} PROPERTIES
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION 1.0.0
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER ${bundleID}
|
||||
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER ${bundleID}
|
||||
)
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// 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
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
@end
|
||||
+52
@@ -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
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#import "ViewController.h"
|
||||
#import "vstgui/lib/vstguiinit.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
VSTGUI::init (CFBundleGetMainBundle ());
|
||||
|
||||
UIScreen* mainScreen = UIScreen.mainScreen;
|
||||
|
||||
UIWindow* window = [[UIWindow alloc] initWithFrame:mainScreen.bounds];
|
||||
window.rootViewController = [ViewController new];
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application
|
||||
{
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application
|
||||
{
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application
|
||||
{
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application
|
||||
{
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application
|
||||
{
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
@end
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// 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
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ViewController : UIViewController
|
||||
|
||||
@end
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
// 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
|
||||
|
||||
#import "ViewController.h"
|
||||
#import "vstgui/vstgui.h"
|
||||
#import "vstgui/vstgui_uidescription.h"
|
||||
#import "vstgui/lib/platform/mac/macglobals.h"
|
||||
#import <sstream>
|
||||
|
||||
using namespace VSTGUI;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
@interface ViewController ()
|
||||
{
|
||||
SharedPointer<CFrame> frame;
|
||||
SharedPointer<UIDescription> uiDesc;
|
||||
}
|
||||
@end
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
@implementation ViewController
|
||||
//------------------------------------------------------------------------
|
||||
- (std::string)templateViewName
|
||||
{
|
||||
CRect size = CRectFromCGRect (self.view.bounds);
|
||||
std::stringstream str;
|
||||
str << static_cast<int> (size.getWidth ()) << "x" << static_cast<int> (size.getHeight ());
|
||||
return str.str ();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
uiDesc = owned (new UIDescription (CResourceDescription ("ios_test.uidesc")));
|
||||
if (!uiDesc->parse ())
|
||||
{
|
||||
@throw [NSException exceptionWithName:@"" reason:@"" userInfo:nil];
|
||||
}
|
||||
|
||||
CRect size = CRectFromCGRect (self.view.bounds);
|
||||
frame = owned (new CFrame (size, nullptr));
|
||||
frame->open ((__bridge void*) (self.view));
|
||||
|
||||
[self didRotateFromInterfaceOrientation:self.interfaceOrientation];
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
|
||||
{
|
||||
frame->setSize (self.view.bounds.size.width, self.view.bounds.size.height);
|
||||
frame->removeAll ();
|
||||
|
||||
SharedPointer<CView> view = uiDesc->createView ([self templateViewName].c_str (), nullptr);
|
||||
if (view == nullptr)
|
||||
@throw [NSException exceptionWithName:@"" reason:@"" userInfo:nil];
|
||||
|
||||
view->setMouseableArea (frame->getViewSize ());
|
||||
view->setViewSize (frame->getViewSize ());
|
||||
frame->addView (view);
|
||||
}
|
||||
|
||||
@end
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<vstgui-ui-description version="1">
|
||||
<fonts>
|
||||
</fonts>
|
||||
<colors>
|
||||
<color name="Background" rgba="#d9d9d9ff"/>
|
||||
</colors>
|
||||
<variables/>
|
||||
<bitmaps/>
|
||||
<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>
|
||||
<custom>
|
||||
<attributes name="UIGridController"/>
|
||||
<attributes SelectedTemplate="1024x768" name="UITemplateController"/>
|
||||
<attributes name="UIAttributesController"/>
|
||||
<attributes EditorSize="0, 0, 1036, 961" SplitViewSize_0_0="0.7904255319148936198558885735110379755497" SplitViewSize_0_1="0.1882978723404255261275608290816307999194" SplitViewSize_1_0="0.5" SplitViewSize_1_1="0.4946808510638298073125440623698523268104" SplitViewSize_2_0="0.8262548262548262689719535956101026386023" SplitViewSize_2_1="0.1689189189189189144180147650331491604447" TabSwitchValue="0" Version="1" name="UIEditController"/>
|
||||
<attributes SelectedRow="22" name="UIViewCreatorDataSource"/>
|
||||
<attributes SelectedRow="0" name="UIColorsDataSource"/>
|
||||
</custom>
|
||||
<template autosize="left right top bottom " background-color="Background" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="320x480" opacity="1" origin="0, 0" size="320, 480" transparent="false">
|
||||
<view autosize="left right top " background-offset="0, 0" class="CSegmentButton" default-value="0.5" font="~ NormalFont" frame-color="~ BlackCColor" frame-width="1" gradient="Default TextButton Gradient" gradient-highlighted="Default TextButton Gradient Highlighted" icon-text-margin="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 20" round-radius="5" segment-names="Segment 1,Segment 2,Segment 3,Segment 4" size="300, 60" style="horizontal" 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="40, 90" round-rect-radius="6" shadow-color="~ RedCColor" size="240, 80" 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 background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CLayeredViewContainer" mouse-enabled="true" opacity="1" origin="70, 210" size="180, 170" transparent="true" z-index="0">
|
||||
<view angle-range="270" angle-start="135" autosize="bottom " background-offset="0, 0" circle-drawing="true" class="CKnob" corona-color="~ WhiteCColor" corona-dash-dot="false" corona-drawing="true" corona-from-center="false" corona-inset="10" corona-inverted="false" corona-outline="true" default-value="0.5" handle-color="~ WhiteCColor" handle-line-width="10" handle-shadow-color="~ GreyCColor" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 10" size="160, 150" transparent="false" value-inset="10" wheel-inc-value="0.1" zoom-factor="1.5"/>
|
||||
</view>
|
||||
</template>
|
||||
<template background-color="Background" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="768x1024" opacity="1" origin="0, 0" size="768, 1024" transparent="false">
|
||||
<view autosize="left right top " background-offset="0, 0" class="CSegmentButton" default-value="0.5" font="~ NormalFont" frame-color="~ BlackCColor" frame-width="1" gradient="Default TextButton Gradient" gradient-highlighted="Default TextButton Gradient Highlighted" icon-text-margin="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 20" round-radius="5" segment-names="Segment 1,Segment 2,Segment 3,Segment 4" size="548, 60" style="horizontal" 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="40, 90" round-rect-radius="6" shadow-color="~ RedCColor" size="490, 80" 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 background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CLayeredViewContainer" mouse-enabled="true" opacity="1" origin="200, 160" size="180, 170" transparent="true" z-index="0">
|
||||
<view angle-range="270" angle-start="135" autosize="bottom " background-offset="0, 0" circle-drawing="true" class="CKnob" corona-color="~ WhiteCColor" corona-dash-dot="false" corona-drawing="true" corona-from-center="false" corona-inset="10" corona-inverted="false" corona-outline="true" default-value="0.5" handle-color="~ WhiteCColor" handle-line-width="10" handle-shadow-color="~ GreyCColor" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 10" size="160, 150" transparent="false" value-inset="10" wheel-inc-value="0.1" zoom-factor="1.5"/>
|
||||
</view>
|
||||
</template>
|
||||
<template background-color="Background" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="1024x768" opacity="1" origin="0, 0" size="1024, 768" transparent="false"/>
|
||||
<template autosize="left right top bottom " background-color="Background" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="480x320" opacity="1" origin="0, 0" size="480, 320" transparent="false">
|
||||
<view autosize="left right top " background-offset="0, 0" class="CSegmentButton" default-value="0.5" font="~ NormalFont" frame-color="~ BlackCColor" frame-width="1" gradient="Default TextButton Gradient" gradient-highlighted="Default TextButton Gradient Highlighted" icon-text-margin="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 20" round-radius="5" segment-names="Segment 1,Segment 2,Segment 3,Segment 4" size="460, 60" style="horizontal" 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="40, 90" round-rect-radius="6" shadow-color="~ RedCColor" size="400, 80" 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 background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CLayeredViewContainer" mouse-enabled="true" opacity="1" origin="150, 160" size="180, 170" transparent="true" z-index="0">
|
||||
<view angle-range="270" angle-start="135" autosize="bottom " background-offset="0, 0" circle-drawing="true" class="CKnob" corona-color="~ WhiteCColor" corona-dash-dot="false" corona-drawing="true" corona-from-center="false" corona-inset="10" corona-inverted="false" corona-outline="true" default-value="0.5" handle-color="~ WhiteCColor" handle-line-width="10" handle-shadow-color="~ GreyCColor" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 10" size="160, 150" transparent="false" value-inset="10" wheel-inc-value="0.1" zoom-factor="1.5"/>
|
||||
</view>
|
||||
</template>
|
||||
<template autosize="left right top bottom " background-color="Background" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="320x568" opacity="1" origin="0, 0" size="320, 568" transparent="false">
|
||||
<view autosize="left right top " background-offset="0, 0" class="CSegmentButton" default-value="0.5" font="~ NormalFont" frame-color="~ BlackCColor" frame-width="1" gradient="Default TextButton Gradient" gradient-highlighted="Default TextButton Gradient Highlighted" icon-text-margin="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 20" round-radius="5" segment-names="Segment 1,Segment 2,Segment 3,Segment 4" size="300, 60" style="horizontal" 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="40, 90" round-rect-radius="6" shadow-color="~ RedCColor" size="240, 80" 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 background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CLayeredViewContainer" mouse-enabled="true" opacity="1" origin="70, 210" size="180, 170" transparent="true" z-index="0">
|
||||
<view angle-range="270" angle-start="135" autosize="bottom " background-offset="0, 0" circle-drawing="true" class="CKnob" corona-color="~ WhiteCColor" corona-dash-dot="false" corona-drawing="true" corona-from-center="false" corona-inset="10" corona-inverted="false" corona-outline="true" default-value="0.5" handle-color="~ WhiteCColor" handle-line-width="10" handle-shadow-color="~ GreyCColor" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 10" size="160, 150" transparent="false" value-inset="10" wheel-inc-value="0.1" zoom-factor="1.5"/>
|
||||
</view>
|
||||
</template>
|
||||
<template autosize="left right top bottom " background-color="Background" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="568x320" opacity="1" origin="0, 0" size="568, 320" transparent="false">
|
||||
<view autosize="left right top " background-offset="0, 0" class="CSegmentButton" default-value="0.5" font="~ NormalFont" frame-color="~ BlackCColor" frame-width="1" gradient="Default TextButton Gradient" gradient-highlighted="Default TextButton Gradient Highlighted" icon-text-margin="0" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 20" round-radius="5" segment-names="Segment 1,Segment 2,Segment 3,Segment 4" size="548, 60" style="horizontal" 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="40, 90" round-rect-radius="6" shadow-color="~ RedCColor" size="490, 80" 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 background-color="~ BlackCColor" background-color-draw-style="filled and stroked" class="CLayeredViewContainer" mouse-enabled="true" opacity="1" origin="200, 160" size="180, 170" transparent="true" z-index="0">
|
||||
<view angle-range="270" angle-start="135" autosize="bottom " background-offset="0, 0" circle-drawing="true" class="CKnob" corona-color="~ WhiteCColor" corona-dash-dot="false" corona-drawing="true" corona-from-center="false" corona-inset="10" corona-inverted="false" corona-outline="true" default-value="0.5" handle-color="~ WhiteCColor" handle-line-width="10" handle-shadow-color="~ GreyCColor" max-value="1" min-value="0" mouse-enabled="true" opacity="1" origin="10, 10" size="160, 150" transparent="false" value-inset="10" wheel-inc-value="0.1" zoom-factor="1.5"/>
|
||||
</view>
|
||||
</template>
|
||||
</vstgui-ui-description>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
##########################################################################################
|
||||
# VSTGUI UIDescriptionEditor Application
|
||||
##########################################################################################
|
||||
option(VSTGUI_UIDESCRIPTIONEDITOR_APPLICATION "UIDescriptionEditorApp Target" OFF)
|
||||
|
||||
if(VSTGUI_UIDESCRIPTIONEDITOR_APPLICATION)
|
||||
|
||||
set(target UIDescriptionEditorApp)
|
||||
|
||||
set(${target}_sources
|
||||
"source/app.cpp"
|
||||
)
|
||||
|
||||
vstgui_add_executable(${target} "${${target}_sources}")
|
||||
vstgui_add_resources(${target} "${target_resources}")
|
||||
vstgui_set_target_infoplist(${target} "resource/Info.plist" "vstgui.uidescriptioneditorapp")
|
||||
vstgui_set_target_rcfile(${target} "resource/winresources.rc")
|
||||
vstgui_set_cxx_version(${target} ${VSTGUI_CXX_VERSION})
|
||||
target_include_directories(${target} PRIVATE ../../../)
|
||||
set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} FOLDER Tests)
|
||||
|
||||
endif(VSTGUI_UIDESCRIPTIONEDITOR_APPLICATION)
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>UIDescriptionEditorApp</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>UIDescriptionEditorApp</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Arne Scheffler. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
+1
@@ -0,0 +1 @@
|
||||
BNDL????
|
||||
+1
@@ -0,0 +1 @@
|
||||
|
||||
+427
@@ -0,0 +1,427 @@
|
||||
// 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 "vstgui/lib/cbitmap.h"
|
||||
#include "vstgui/lib/ccolor.h"
|
||||
#include "vstgui/lib/cframe.h"
|
||||
#include "vstgui/lib/malloc.h"
|
||||
#include "vstgui/lib/platform/common/genericoptionmenu.h"
|
||||
#include "vstgui/lib/platform/iplatformframe.h"
|
||||
#include "vstgui/standalone/include/helpers/appdelegate.h"
|
||||
#include "vstgui/standalone/include/helpers/menubuilder.h"
|
||||
#include "vstgui/standalone/include/helpers/uidesc/modelbinding.h"
|
||||
#include "vstgui/standalone/include/helpers/value.h"
|
||||
#include "vstgui/standalone/include/helpers/windowcontroller.h"
|
||||
#include "vstgui/standalone/include/ialertbox.h"
|
||||
#include "vstgui/standalone/include/iapplication.h"
|
||||
#include "vstgui/standalone/include/icommand.h"
|
||||
#include "vstgui/uidescription/cstream.h"
|
||||
#include "vstgui/uidescription/detail/uijsonpersistence.h"
|
||||
#include "vstgui/uidescription/detail/uixmlpersistence.h"
|
||||
#include "vstgui/uidescription/editing/uieditcontroller.h"
|
||||
#include "vstgui/uidescription/editing/uieditmenucontroller.h"
|
||||
#include "vstgui/uidescription/editing/uiundomanager.h"
|
||||
#include "vstgui/uidescription/uicontentprovider.h"
|
||||
#include "vstgui/uidescription/uidescription.h"
|
||||
#include <chrono>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
namespace Standalone {
|
||||
|
||||
using namespace Application;
|
||||
|
||||
#if VSTGUI_LIVE_EDITING
|
||||
//------------------------------------------------------------------------
|
||||
static void makeAndOpenWindow (bool darkTheme);
|
||||
|
||||
static constexpr IdStringPtr RunJSONXMLBenchmark = "Run JSON/XML Benchmark";
|
||||
static const Command BenchmarkCommand {CommandGroup::File, RunJSONXMLBenchmark};
|
||||
|
||||
static constexpr IdStringPtr CommandNameLightTheme = "Light Theme";
|
||||
static constexpr IdStringPtr CommandNameDarkTheme = "Dark Theme";
|
||||
static constexpr IdStringPtr CommandCategoryTheme = "Theme";
|
||||
static const Command CommandLightTheme {CommandCategoryTheme, CommandNameLightTheme};
|
||||
static const Command CommandDarkTheme {CommandCategoryTheme, CommandNameDarkTheme};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class Controller : public WindowControllerAdapter, public ICommandHandler
|
||||
{
|
||||
public:
|
||||
Controller (bool darkTheme = false) : useDarkTheme (darkTheme)
|
||||
{
|
||||
IApplication::instance ().registerCommand (Commands::SaveDocument, 's');
|
||||
IApplication::instance ().registerCommand (Commands::RevertDocument, 0);
|
||||
IApplication::instance ().registerCommand (CommandLightTheme, 0);
|
||||
IApplication::instance ().registerCommand (CommandDarkTheme, 0);
|
||||
#if VSTGUI_ENABLE_XML_PARSER
|
||||
IApplication::instance ().registerCommand (BenchmarkCommand, 0);
|
||||
#endif
|
||||
|
||||
std::string basePath = __FILE__;
|
||||
unixfyPath (basePath);
|
||||
removeLastPathComponent (basePath);
|
||||
removeLastPathComponent (basePath);
|
||||
removeLastPathComponent (basePath);
|
||||
removeLastPathComponent (basePath);
|
||||
basePath += "/uidescription/editing/";
|
||||
descPath = basePath + "uidescriptioneditor.uidesc";
|
||||
lightResPath = basePath + "uidescriptioneditor_res_light.uidesc";
|
||||
darkResPath = basePath + "uidescriptioneditor_res_dark.uidesc";
|
||||
}
|
||||
|
||||
bool init ()
|
||||
{
|
||||
uidesc = makeOwned<UIDescription> (descPath.data ());
|
||||
if (!uidesc->parse ())
|
||||
{
|
||||
// TODO: show alert about error
|
||||
IApplication::instance ().quit ();
|
||||
return false;
|
||||
}
|
||||
uidesc->setFilePath (descPath.data ());
|
||||
lightResDesc = makeOwned<UIDescription> (lightResPath.data ());
|
||||
if (!lightResDesc->parse ())
|
||||
{
|
||||
// TODO: show alert about error
|
||||
IApplication::instance ().quit ();
|
||||
return false;
|
||||
}
|
||||
darkResDesc = makeOwned<UIDescription> (darkResPath.data ());
|
||||
if (!darkResDesc->parse ())
|
||||
{
|
||||
darkResDesc = nullptr;
|
||||
}
|
||||
|
||||
if (useDarkTheme && darkResDesc)
|
||||
{
|
||||
uidesc->setSharedResources (darkResDesc);
|
||||
}
|
||||
else
|
||||
{
|
||||
uidesc->setSharedResources (lightResDesc);
|
||||
}
|
||||
editController = makeOwned<UIEditController> (uidesc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool save ()
|
||||
{
|
||||
if (uidesc->save (descPath.data (), UIDescription::kWriteImagesIntoUIDescFile))
|
||||
{
|
||||
if (useDarkTheme && darkResDesc)
|
||||
{
|
||||
darkResDesc->save (darkResPath.data (), UIDescription::kWriteImagesIntoUIDescFile);
|
||||
}
|
||||
else if (lightResDesc)
|
||||
{
|
||||
lightResDesc->save (lightResPath.data (),
|
||||
UIDescription::kWriteImagesIntoUIDescFile);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void beforeShow (IWindow& window) override
|
||||
{
|
||||
win = &window;
|
||||
CRect r;
|
||||
r.setSize (window.getSize ());
|
||||
auto frame = makeOwned<CFrame> (r, nullptr);
|
||||
frame->enableTooltips (true);
|
||||
editController->setDarkTheme (useDarkTheme);
|
||||
if (auto view = editController->createEditView ())
|
||||
{
|
||||
editController->remember (); // view will forget it too
|
||||
frame->setViewSize (view->getViewSize ());
|
||||
frame->addView (view);
|
||||
window.setContentView (frame);
|
||||
|
||||
auto focusDrawingSettings = uidesc->getFocusDrawingSettings ();
|
||||
if (focusDrawingSettings.enabled)
|
||||
{
|
||||
CColor focusColor;
|
||||
if (uidesc->getColor (focusDrawingSettings.colorName, focusColor))
|
||||
frame->setFocusColor (focusColor);
|
||||
frame->setFocusWidth (focusDrawingSettings.width);
|
||||
frame->setFocusDrawingEnabled (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class SaveChanges
|
||||
{
|
||||
Save,
|
||||
Cancel,
|
||||
DontSave,
|
||||
};
|
||||
|
||||
SaveChanges askSaveChanges ()
|
||||
{
|
||||
if (win && !editController->getUndoManager ()->isSavePosition ())
|
||||
{
|
||||
AlertBoxConfig config;
|
||||
config.headline = "There are unsaved changes.";
|
||||
config.description = "Do you want to save the changes ?";
|
||||
config.defaultButton = "Save";
|
||||
config.secondButton = "Cancel";
|
||||
config.thirdButton = "Don't Save";
|
||||
auto result = IApplication::instance ().showAlertBox (config);
|
||||
switch (result)
|
||||
{
|
||||
case AlertResult::DefaultButton:
|
||||
{
|
||||
save ();
|
||||
return SaveChanges::Save;
|
||||
}
|
||||
case AlertResult::SecondButton: return SaveChanges::Cancel;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return SaveChanges::DontSave;
|
||||
}
|
||||
|
||||
bool checkSaveChanges ()
|
||||
{
|
||||
switch (askSaveChanges ())
|
||||
{
|
||||
case SaveChanges::Save:
|
||||
{
|
||||
save ();
|
||||
return true;
|
||||
}
|
||||
case SaveChanges::Cancel: return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool canClose (const IWindow& window) override
|
||||
{
|
||||
return checkSaveChanges ();
|
||||
}
|
||||
|
||||
void onClosed (const IWindow& window) override
|
||||
{
|
||||
if (IApplication::instance ().getWindows ().empty ())
|
||||
IApplication::instance ().quit ();
|
||||
}
|
||||
|
||||
bool canHandleCommand (const Command& command) override
|
||||
{
|
||||
if (command == Commands::SaveDocument)
|
||||
return true;
|
||||
if (command == Commands::Undo)
|
||||
return editController->getUndoManager ()->canUndo ();
|
||||
if (command == Commands::Redo)
|
||||
return editController->getUndoManager ()->canRedo ();
|
||||
if (command == Commands::RevertDocument)
|
||||
return !editController->getUndoManager ()->isSavePosition ();
|
||||
if (command == CommandLightTheme && lightResDesc)
|
||||
return uidesc->getSharedResources () != lightResDesc;
|
||||
if (command == CommandDarkTheme && darkResDesc)
|
||||
return uidesc->getSharedResources () != darkResDesc;
|
||||
if (command == BenchmarkCommand)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void reopenWindow ()
|
||||
{
|
||||
makeAndOpenWindow (useDarkTheme);
|
||||
if (auto window = win)
|
||||
{
|
||||
win = nullptr;
|
||||
window->close ();
|
||||
}
|
||||
}
|
||||
|
||||
bool handleCommand (const Command& command) override
|
||||
{
|
||||
if (command == Commands::SaveDocument)
|
||||
return save ();
|
||||
if (command == Commands::Undo)
|
||||
return editController->getMenuController ()->handleCommand ("Edit", "Undo");
|
||||
if (command == Commands::Redo)
|
||||
return editController->getMenuController ()->handleCommand ("Edit", "Redo");
|
||||
if (command == Commands::RevertDocument)
|
||||
{
|
||||
reopenWindow ();
|
||||
return true;
|
||||
}
|
||||
if (command == CommandLightTheme)
|
||||
{
|
||||
if (!checkSaveChanges ())
|
||||
return true;
|
||||
useDarkTheme = false;
|
||||
reopenWindow ();
|
||||
return true;
|
||||
}
|
||||
if (command == CommandDarkTheme)
|
||||
{
|
||||
if (!checkSaveChanges ())
|
||||
return true;
|
||||
useDarkTheme = true;
|
||||
reopenWindow ();
|
||||
return true;
|
||||
}
|
||||
if (command == BenchmarkCommand)
|
||||
{
|
||||
runBenchmark ();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void onSetContentView (IWindow& window, const SharedPointer<CFrame>& contentView) override
|
||||
{
|
||||
if (auto platformFrame = contentView->getPlatformFrame ())
|
||||
{
|
||||
platformFrame->setupGenericOptionMenu (true);
|
||||
}
|
||||
}
|
||||
|
||||
void runBenchmark ()
|
||||
{
|
||||
#if VSTGUI_ENABLE_XML_PARSER
|
||||
static constexpr auto iterations = 100u;
|
||||
|
||||
if (!uidesc)
|
||||
return;
|
||||
auto node = uidesc->getRootNode ();
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
CMemoryStream xmlData (1024, 1024, false);
|
||||
CMemoryStream jsonData (1024, 1024, false);
|
||||
|
||||
Detail::UIXMLDescWriter xmlWriter;
|
||||
if (!xmlWriter.write (xmlData, node))
|
||||
return;
|
||||
xmlData.rewind ();
|
||||
|
||||
if (!Detail::UIJsonDescWriter::write (jsonData, node))
|
||||
return;
|
||||
jsonData.end ();
|
||||
jsonData.rewind ();
|
||||
|
||||
InputStreamContentProvider xmlContentProvider (xmlData);
|
||||
|
||||
auto xmlStartTime = std::chrono::high_resolution_clock::now ();
|
||||
for (auto i = 0u; i < iterations; ++i)
|
||||
{
|
||||
xmlData.rewind ();
|
||||
Detail::UIXMLParser parser;
|
||||
if (!parser.parse (&xmlContentProvider))
|
||||
return;
|
||||
}
|
||||
auto xmlEndTime = std::chrono::high_resolution_clock::now ();
|
||||
|
||||
InputStreamContentProvider jsonContentProvider (jsonData);
|
||||
|
||||
auto jsonStartTime = std::chrono::high_resolution_clock::now ();
|
||||
for (auto i = 0u; i < iterations; ++i)
|
||||
{
|
||||
jsonData.rewind ();
|
||||
if (!Detail::UIJsonDescReader::read (jsonContentProvider))
|
||||
return;
|
||||
}
|
||||
auto jsonEndTime = std::chrono::high_resolution_clock::now ();
|
||||
|
||||
auto xmlDuration =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds> (xmlEndTime - xmlStartTime)
|
||||
.count ();
|
||||
auto jsonDuration =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds> (jsonEndTime - jsonStartTime)
|
||||
.count ();
|
||||
|
||||
printf ("xml :%lld\n", xmlDuration);
|
||||
printf ("json:%lld\n", jsonDuration);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string descPath;
|
||||
std::string lightResPath;
|
||||
std::string darkResPath;
|
||||
SharedPointer<UIDescription> uidesc;
|
||||
SharedPointer<UIDescription> lightResDesc;
|
||||
SharedPointer<UIDescription> darkResDesc;
|
||||
SharedPointer<UIEditController> editController;
|
||||
IWindow* win {nullptr};
|
||||
bool useDarkTheme {false};
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void makeAndOpenWindow (bool darkTheme)
|
||||
{
|
||||
auto controller = std::make_shared<Controller> (darkTheme);
|
||||
if (controller->init ())
|
||||
{
|
||||
WindowConfiguration config;
|
||||
config.style.border ().size ().close ().centered ();
|
||||
config.title = "UIDescriptionEditor";
|
||||
config.autoSaveFrameName = "UIDescriptionEditorWindowFrame";
|
||||
config.size = {500, 500};
|
||||
if (auto window = IApplication::instance ().createWindow (config, controller))
|
||||
window->show ();
|
||||
else
|
||||
IApplication::instance ().quit ();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class UIDescriptionEditorApp : public DelegateAdapter, public MenuBuilderAdapter
|
||||
{
|
||||
public:
|
||||
UIDescriptionEditorApp ()
|
||||
: DelegateAdapter ({"UIDescriptionEditorApp", "1.0.0", "vstgui.uidescriptioneditorapp"})
|
||||
{
|
||||
}
|
||||
|
||||
bool prependMenuSeparator (const Interface& context, const Command& cmd) const override
|
||||
{
|
||||
if (cmd == Commands::CloseWindow || cmd == BenchmarkCommand)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
SortFunction getCommandGroupSortFunction (const Interface& context,
|
||||
const UTF8String& group) const override
|
||||
{
|
||||
if (group == CommandGroup::File)
|
||||
{
|
||||
return [] (const UTF8String& lhs, const UTF8String& rhs) {
|
||||
static const auto order = {
|
||||
Commands::NewDocument.name, Commands::OpenDocument.name,
|
||||
Commands::SaveDocument.name, Commands::SaveDocumentAs.name,
|
||||
Commands::RevertDocument.name, BenchmarkCommand.name,
|
||||
Commands::CloseWindow.name};
|
||||
auto leftIndex = std::find (order.begin (), order.end (), lhs);
|
||||
auto rightIndex = std::find (order.begin (), order.end (), rhs);
|
||||
return std::distance (leftIndex, rightIndex) > 0;
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void finishLaunching () override
|
||||
{
|
||||
#if VSTGUI_LIVE_EDITING
|
||||
makeAndOpenWindow (false);
|
||||
#else
|
||||
IApplication::instance ().quit ();
|
||||
AlertBoxConfig config;
|
||||
config.headline = "UIDescriptionEditorApp only works in Debug mode";
|
||||
IApplication::instance ().showAlertBox (config);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
static Init gAppDelegate (std::make_unique<UIDescriptionEditorApp> ());
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // Standalone
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,229 @@
|
||||
##########################################################################################
|
||||
# VSTGUI Unittests
|
||||
##########################################################################################
|
||||
|
||||
set(target unittests)
|
||||
|
||||
set(VSTGUI_TEST_BASE "")
|
||||
#set(VSTGUI_TEST_BASE "${VSTGUI_TEST_BASE}")
|
||||
|
||||
set(${target}_sources
|
||||
"${VSTGUI_TEST_BASE}unittests.cpp"
|
||||
"${VSTGUI_TEST_BASE}unittests.h"
|
||||
"${VSTGUI_TEST_BASE}lib/animation/animations_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/animation/animator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/animation/timingfunction_tests.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/ccheckbox_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/ccontrol_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/ckickbutton_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/clistcontrol_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/conoffbutton_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/coptionmenu_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/csegmentbutton_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/ctextbutton_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/controls/cxypad_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/algorithm_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/cbitmap_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/cbuttonstate_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/cclipboard_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/ccolor_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/cframe_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/cinvalidrectlist_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/clinestyle_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/cpoint_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/crect_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/csplitview_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/cview_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/cviewcontainer_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/enumbitset_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/event_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/eventhelpers.h"
|
||||
"${VSTGUI_TEST_BASE}lib/gridlayout_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/idependency_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/pixelbufferconverter_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/platform_helper.h"
|
||||
"${VSTGUI_TEST_BASE}lib/task_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/utf8string_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}lib/utf8stringview_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/canimationsplashscreencreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/canimknobcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/ccheckboxcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/ccontrolcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cgradientviewcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/chorizontalswitchcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/ckickbuttoncreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cknobcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/clayeredviewcontainercreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cmoviebitmapcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cmoviebuttoncreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cmultilinetextlabelcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/conoffbuttoncreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/coptionmenucreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cparamdisplaycreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/crockerswitchcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/crowcolumnviewcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cscrollviewcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/csearchtexteditcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/csegmentbuttoncreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cshadowviewcontainercreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cslidercreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/csplitviewcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/ctextbuttoncreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/ctexteditcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/ctextlabelcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cverticalswitchcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cviewcontainercreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cviewcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cvumetercreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/cxypadcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/helpers.h"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/stringlistcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/uiviewcreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewcreator/uiviewswitchcontainercreator_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/base64codec.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/cstream_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/delegationcontroller_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiattributes_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uidescription_addon_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uidescription_json_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uidescription_test_helper.h"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uidescription_xml_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uidescriptionadapter.h"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewfactory_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/uiviewswitchcontainer_test.cpp"
|
||||
"${VSTGUI_TEST_BASE}uidescription/xmlparser_test.cpp"
|
||||
)
|
||||
|
||||
##########################################################################################
|
||||
if(CMAKE_HOST_APPLE)
|
||||
set(${target}_sources
|
||||
${${target}_sources}
|
||||
"${VSTGUI_TEST_BASE}lib/platform_helper_mac.mm"
|
||||
)
|
||||
|
||||
set(${target}_PLATFORM_LIBS
|
||||
"-framework Cocoa"
|
||||
"-framework OpenGL"
|
||||
"-framework QuartzCore"
|
||||
"-framework Accelerate"
|
||||
)
|
||||
endif()
|
||||
|
||||
##########################################################################################
|
||||
if(MSVC)
|
||||
set(${target}_sources
|
||||
${${target}_sources}
|
||||
"${VSTGUI_TEST_BASE}lib/platform_helper_win32.cpp"
|
||||
"${VSTGUI_TEST_BASE}../../vstgui_win32.cpp"
|
||||
)
|
||||
endif()
|
||||
|
||||
##########################################################################################
|
||||
if(UNIX AND NOT CMAKE_HOST_APPLE)
|
||||
set(${target}_sources
|
||||
${${target}_sources}
|
||||
"${VSTGUI_TEST_BASE}lib/platform_helper_linux.cpp"
|
||||
"${VSTGUI_TEST_BASE}../../vstgui_linux.cpp"
|
||||
)
|
||||
set(${target}_PLATFORM_LIBS
|
||||
${LINUX_LIBRARIES}
|
||||
stdc++fs
|
||||
pthread
|
||||
dl
|
||||
)
|
||||
endif()
|
||||
|
||||
##########################################################################################
|
||||
|
||||
if(XCODE)
|
||||
option(VSTGUI_USE_XCODE_XCTEST "Use integrated Xcode testing" ON)
|
||||
endif(XCODE)
|
||||
|
||||
if(VSTGUI_USE_XCODE_XCTEST)
|
||||
include(FindXCTest REQUIRED)
|
||||
|
||||
set(${target}_sources
|
||||
"${${target}_sources}"
|
||||
"${VSTGUI_TEST_BASE}xcodetestintegration.mm"
|
||||
)
|
||||
|
||||
xctest_add_bundle(${target} vstgui ${${target}_sources})
|
||||
vstgui_set_cxx_version(${target} ${VSTGUI_CXX_VERSION})
|
||||
target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS} ENABLE_UNIT_TESTS=1 VSTGUI_LIVE_EDITING=1)
|
||||
target_link_libraries(${target} PRIVATE
|
||||
${${target}_PLATFORM_LIBS}
|
||||
vstgui
|
||||
vstgui_uidescription
|
||||
)
|
||||
|
||||
vstgui_source_group_by_folder(${target})
|
||||
|
||||
else()
|
||||
if(CMAKE_HOST_APPLE)
|
||||
set(${target}_sources
|
||||
${${target}_sources}
|
||||
"${VSTGUI_TEST_BASE}../../vstgui_mac.mm"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(${target}_sources
|
||||
${${target}_sources}
|
||||
"${VSTGUI_TEST_BASE}../../vstgui_uidescription.cpp"
|
||||
"${VSTGUI_TEST_BASE}unittestmain.cpp"
|
||||
)
|
||||
|
||||
add_executable(${target} ${${target}_sources})
|
||||
target_link_libraries(${target} PRIVATE
|
||||
${${target}_PLATFORM_LIBS}
|
||||
)
|
||||
|
||||
vstgui_set_cxx_version(${target} ${VSTGUI_CXX_VERSION})
|
||||
target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS} ENABLE_UNIT_TESTS=1 VSTGUI_LIVE_EDITING=1)
|
||||
vstgui_source_group_by_folder(${target})
|
||||
|
||||
add_custom_command(TARGET ${target} POST_BUILD COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittests")
|
||||
|
||||
##########################################################################################
|
||||
if(UNIX AND NOT CMAKE_HOST_APPLE)
|
||||
target_include_directories(${target} PRIVATE ${X11_INCLUDE_DIR})
|
||||
target_include_directories(${target} PRIVATE ${GTK3_INCLUDE_DIRS})
|
||||
target_include_directories(${target} PRIVATE ${GTKMM3_INCLUDE_DIRS})
|
||||
target_include_directories(${target} PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_compile_options(${target} PRIVATE /bigobj)
|
||||
endif()
|
||||
endif(VSTGUI_USE_XCODE_XCTEST)
|
||||
|
||||
if(CMAKE_HOST_APPLE)
|
||||
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 11.0)
|
||||
target_compile_definitions(${target} PRIVATE "VSTGUI_USE_OBJC_UTTYPE")
|
||||
target_link_libraries(${target} PRIVATE
|
||||
"-framework UniformTypeIdentifiers"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#if(CMAKE_HOST_APPLE)
|
||||
# option(VSTGUI_ENABLE_CODECOVERAGE "Generate Code Coverage Data" OFF)
|
||||
# if(VSTGUI_ENABLE_CODECOVERAGE)
|
||||
# add_executable(codecoverage ${${target}_sources})
|
||||
#
|
||||
# set(target codecoverage)
|
||||
#
|
||||
# target_link_libraries(${target}
|
||||
# "-framework Cocoa"
|
||||
# "-framework OpenGL"
|
||||
# "-framework QuartzCore"
|
||||
# "-framework Accelerate"
|
||||
# "--coverage"
|
||||
# )
|
||||
#
|
||||
# vstgui_set_cxx_version(${target} 14)
|
||||
# target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS} ENABLE_UNIT_TESTS=1 VSTGUI_LIVE_EDITING=1 VSTGUI_ENABLE_DEPRECATED_METHODS=0)
|
||||
# vstgui_source_group_by_folder(${target})
|
||||
# target_compile_options(${target} PUBLIC "--coverage")
|
||||
# add_custom_command(TARGET ${target} POST_BUILD COMMAND "/usr/bin/ruby" "${CMAKE_CURRENT_SOURCE_DIR}/lcov/generate.rb" "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/vstgui.build/Debug/codecoverage.build/Objects-normal/x86_64" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/coverage_output" VERBATIM)
|
||||
# endif()
|
||||
#endif()
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Copyright (c) International Business Machines Corp., 2002
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or (at
|
||||
# your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# gendesc
|
||||
#
|
||||
# This script creates a description file as understood by genhtml.
|
||||
# Input file format:
|
||||
#
|
||||
# For each test case:
|
||||
# <test name><optional whitespace>
|
||||
# <at least one whitespace character (blank/tab)><test description>
|
||||
#
|
||||
# Actual description may consist of several lines. By default, output is
|
||||
# written to stdout. Test names consist of alphanumeric characters
|
||||
# including _ and -.
|
||||
#
|
||||
#
|
||||
# History:
|
||||
# 2002-09-02: created by Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
|
||||
#
|
||||
|
||||
use strict;
|
||||
use File::Basename;
|
||||
use Getopt::Long;
|
||||
use Cwd qw/abs_path/;
|
||||
|
||||
|
||||
# Constants
|
||||
our $tool_dir = abs_path(dirname($0));
|
||||
our $lcov_version = "LCOV version 1.13";
|
||||
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
|
||||
our $tool_name = basename($0);
|
||||
|
||||
|
||||
# Prototypes
|
||||
sub print_usage(*);
|
||||
sub gen_desc();
|
||||
sub warn_handler($);
|
||||
sub die_handler($);
|
||||
|
||||
|
||||
# Global variables
|
||||
our $help;
|
||||
our $version;
|
||||
our $output_filename;
|
||||
our $input_filename;
|
||||
|
||||
|
||||
#
|
||||
# Code entry point
|
||||
#
|
||||
|
||||
$SIG{__WARN__} = \&warn_handler;
|
||||
$SIG{__DIE__} = \&die_handler;
|
||||
|
||||
# Parse command line options
|
||||
if (!GetOptions("output-filename=s" => \$output_filename,
|
||||
"version" =>\$version,
|
||||
"help|?" => \$help
|
||||
))
|
||||
{
|
||||
print(STDERR "Use $tool_name --help to get usage information\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$input_filename = $ARGV[0];
|
||||
|
||||
# Check for help option
|
||||
if ($help)
|
||||
{
|
||||
print_usage(*STDOUT);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
# Check for version option
|
||||
if ($version)
|
||||
{
|
||||
print("$tool_name: $lcov_version\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
# Check for input filename
|
||||
if (!$input_filename)
|
||||
{
|
||||
die("No input filename specified\n".
|
||||
"Use $tool_name --help to get usage information\n");
|
||||
}
|
||||
|
||||
# Do something
|
||||
gen_desc();
|
||||
|
||||
|
||||
#
|
||||
# print_usage(handle)
|
||||
#
|
||||
# Write out command line usage information to given filehandle.
|
||||
#
|
||||
|
||||
sub print_usage(*)
|
||||
{
|
||||
local *HANDLE = $_[0];
|
||||
|
||||
print(HANDLE <<END_OF_USAGE)
|
||||
Usage: $tool_name [OPTIONS] INPUTFILE
|
||||
|
||||
Convert a test case description file into a format as understood by genhtml.
|
||||
|
||||
-h, --help Print this help, then exit
|
||||
-v, --version Print version number, then exit
|
||||
-o, --output-filename FILENAME Write description to FILENAME
|
||||
|
||||
For more information see: $lcov_url
|
||||
END_OF_USAGE
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# gen_desc()
|
||||
#
|
||||
# Read text file INPUT_FILENAME and convert the contained description to a
|
||||
# format as understood by genhtml, i.e.
|
||||
#
|
||||
# TN:<test name>
|
||||
# TD:<test description>
|
||||
#
|
||||
# If defined, write output to OUTPUT_FILENAME, otherwise to stdout.
|
||||
#
|
||||
# Die on error.
|
||||
#
|
||||
|
||||
sub gen_desc()
|
||||
{
|
||||
local *INPUT_HANDLE;
|
||||
local *OUTPUT_HANDLE;
|
||||
my $empty_line = "ignore";
|
||||
|
||||
open(INPUT_HANDLE, "<", $input_filename)
|
||||
or die("ERROR: cannot open $input_filename!\n");
|
||||
|
||||
# Open output file for writing
|
||||
if ($output_filename)
|
||||
{
|
||||
open(OUTPUT_HANDLE, ">", $output_filename)
|
||||
or die("ERROR: cannot create $output_filename!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
*OUTPUT_HANDLE = *STDOUT;
|
||||
}
|
||||
|
||||
# Process all lines in input file
|
||||
while (<INPUT_HANDLE>)
|
||||
{
|
||||
chomp($_);
|
||||
|
||||
if (/^(\w[\w-]*)(\s*)$/)
|
||||
{
|
||||
# Matched test name
|
||||
# Name starts with alphanum or _, continues with
|
||||
# alphanum, _ or -
|
||||
print(OUTPUT_HANDLE "TN: $1\n");
|
||||
$empty_line = "ignore";
|
||||
}
|
||||
elsif (/^(\s+)(\S.*?)\s*$/)
|
||||
{
|
||||
# Matched test description
|
||||
if ($empty_line eq "insert")
|
||||
{
|
||||
# Write preserved empty line
|
||||
print(OUTPUT_HANDLE "TD: \n");
|
||||
}
|
||||
print(OUTPUT_HANDLE "TD: $2\n");
|
||||
$empty_line = "observe";
|
||||
}
|
||||
elsif (/^\s*$/)
|
||||
{
|
||||
# Matched empty line to preserve paragraph separation
|
||||
# inside description text
|
||||
if ($empty_line eq "observe")
|
||||
{
|
||||
$empty_line = "insert";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Close output file if defined
|
||||
if ($output_filename)
|
||||
{
|
||||
close(OUTPUT_HANDLE);
|
||||
}
|
||||
|
||||
close(INPUT_HANDLE);
|
||||
}
|
||||
|
||||
sub warn_handler($)
|
||||
{
|
||||
my ($msg) = @_;
|
||||
|
||||
warn("$tool_name: $msg");
|
||||
}
|
||||
|
||||
sub die_handler($)
|
||||
{
|
||||
my ($msg) = @_;
|
||||
|
||||
die("$tool_name: $msg");
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
VSTGUI_DIR = File.expand_path(ARGV[0])
|
||||
OBJ_DIR = File.expand_path(ARGV[1])
|
||||
UNITTEST_EXE = File.expand_path(ARGV[2])
|
||||
OUTPUT_DIR = File.expand_path(ARGV[3])
|
||||
SCRIPT_DIR = File.expand_path(File.dirname(__FILE__))
|
||||
puts "Generating Code Coverage with:"
|
||||
puts "VSTGUI_DIR=" + VSTGUI_DIR
|
||||
puts "OBJ_DIR=" + OBJ_DIR
|
||||
puts "UNITTEST_EXE=" + UNITTEST_EXE
|
||||
puts "SCRIPT_DIR=" + SCRIPT_DIR
|
||||
|
||||
def removeDataFromTrace(infoFile, directory)
|
||||
puts "Removing test coverage from #{directory}"
|
||||
system ("./lcov --remove #{infoFile} --output-file #{infoFile} #{directory}/*")
|
||||
Dir.foreach(directory) { |path|
|
||||
if (path != ".." && path != ".")
|
||||
d = File.join(directory, path)
|
||||
if (File.directory?(d))
|
||||
removeDataFromTrace(infoFile, d)
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
begin
|
||||
|
||||
system (UNITTEST_EXE)
|
||||
|
||||
if ($? != 0)
|
||||
raise "unittest error"
|
||||
end
|
||||
|
||||
Dir.chdir (SCRIPT_DIR)
|
||||
|
||||
COVERAGE_FILE = "vstgui-coverage.info"
|
||||
|
||||
system ("./lcov --capture --no-external --base-directory #{VSTGUI_DIR} --directory #{OBJ_DIR} --output-file vstgui-coverage.info")
|
||||
system ("./lcov --remove #{COVERAGE_FILE} --output-file #{COVERAGE_FILE} #{VSTGUI_DIR}/vstgui_mac.mm")
|
||||
removeDataFromTrace(COVERAGE_FILE, "#{VSTGUI_DIR}/uidescription/expat")
|
||||
removeDataFromTrace(COVERAGE_FILE, "#{VSTGUI_DIR}/tests/unittest")
|
||||
removeDataFromTrace(COVERAGE_FILE, "#{VSTGUI_DIR}/lib/platform")
|
||||
# system ("./lcov --remove vstgui-coverage.info --output-file vstgui-coverage.info #{VSTGUI_DIR}/tests/unittest/**")
|
||||
if ($? != 0)
|
||||
raise "lcov error"
|
||||
end
|
||||
|
||||
|
||||
puts "Generating report..."
|
||||
system ("./genhtml vstgui-coverage.info -t 'VSTGUI Test Coverage' --num-spaces 4 --demangle-cpp --output-directory #{OUTPUT_DIR}")
|
||||
|
||||
if ($? != 0)
|
||||
raise "genhtml error"
|
||||
end
|
||||
|
||||
ensure
|
||||
|
||||
Dir.foreach(OBJ_DIR) { |f|
|
||||
ext = File.extname(f)
|
||||
if (ext == ".gcda")
|
||||
File.delete (File.join(OBJ_DIR, f))
|
||||
end
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
+6060
File diff suppressed because it is too large
Load Diff
+3862
File diff suppressed because it is too large
Load Diff
+388
@@ -0,0 +1,388 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Copyright (c) International Business Machines Corp., 2002
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or (at
|
||||
# your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# genpng
|
||||
#
|
||||
# This script creates an overview PNG image of a source code file by
|
||||
# representing each source code character by a single pixel.
|
||||
#
|
||||
# Note that the Perl module GD.pm is required for this script to work.
|
||||
# It may be obtained from http://www.cpan.org
|
||||
#
|
||||
# History:
|
||||
# 2002-08-26: created by Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
|
||||
#
|
||||
|
||||
use strict;
|
||||
use File::Basename;
|
||||
use Getopt::Long;
|
||||
use Cwd qw/abs_path/;
|
||||
|
||||
|
||||
# Constants
|
||||
our $tool_dir = abs_path(dirname($0));
|
||||
our $lcov_version = "LCOV version 1.13";
|
||||
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
|
||||
our $tool_name = basename($0);
|
||||
|
||||
|
||||
# Prototypes
|
||||
sub gen_png($$$@);
|
||||
sub check_and_load_module($);
|
||||
sub genpng_print_usage(*);
|
||||
sub genpng_process_file($$$$);
|
||||
sub genpng_warn_handler($);
|
||||
sub genpng_die_handler($);
|
||||
|
||||
|
||||
#
|
||||
# Code entry point
|
||||
#
|
||||
|
||||
# Check whether required module GD.pm is installed
|
||||
if (check_and_load_module("GD"))
|
||||
{
|
||||
# Note: cannot use die() to print this message because inserting this
|
||||
# code into another script via do() would not fail as required!
|
||||
print(STDERR <<END_OF_TEXT)
|
||||
ERROR: required module GD.pm not found on this system (see www.cpan.org).
|
||||
END_OF_TEXT
|
||||
;
|
||||
exit(2);
|
||||
}
|
||||
|
||||
# Check whether we're called from the command line or from another script
|
||||
if (!caller)
|
||||
{
|
||||
my $filename;
|
||||
my $tab_size = 4;
|
||||
my $width = 80;
|
||||
my $out_filename;
|
||||
my $help;
|
||||
my $version;
|
||||
|
||||
$SIG{__WARN__} = \&genpng_warn_handler;
|
||||
$SIG{__DIE__} = \&genpng_die_handler;
|
||||
|
||||
# Parse command line options
|
||||
if (!GetOptions("tab-size=i" => \$tab_size,
|
||||
"width=i" => \$width,
|
||||
"output-filename=s" => \$out_filename,
|
||||
"help" => \$help,
|
||||
"version" => \$version))
|
||||
{
|
||||
print(STDERR "Use $tool_name --help to get usage ".
|
||||
"information\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$filename = $ARGV[0];
|
||||
|
||||
# Check for help flag
|
||||
if ($help)
|
||||
{
|
||||
genpng_print_usage(*STDOUT);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
# Check for version flag
|
||||
if ($version)
|
||||
{
|
||||
print("$tool_name: $lcov_version\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
# Check options
|
||||
if (!$filename)
|
||||
{
|
||||
die("No filename specified\n");
|
||||
}
|
||||
|
||||
# Check for output filename
|
||||
if (!$out_filename)
|
||||
{
|
||||
$out_filename = "$filename.png";
|
||||
}
|
||||
|
||||
genpng_process_file($filename, $out_filename, $width, $tab_size);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# genpng_print_usage(handle)
|
||||
#
|
||||
# Write out command line usage information to given filehandle.
|
||||
#
|
||||
|
||||
sub genpng_print_usage(*)
|
||||
{
|
||||
local *HANDLE = $_[0];
|
||||
|
||||
print(HANDLE <<END_OF_USAGE)
|
||||
Usage: $tool_name [OPTIONS] SOURCEFILE
|
||||
|
||||
Create an overview image for a given source code file of either plain text
|
||||
or .gcov file format.
|
||||
|
||||
-h, --help Print this help, then exit
|
||||
-v, --version Print version number, then exit
|
||||
-t, --tab-size TABSIZE Use TABSIZE spaces in place of tab
|
||||
-w, --width WIDTH Set width of output image to WIDTH pixel
|
||||
-o, --output-filename FILENAME Write image to FILENAME
|
||||
|
||||
For more information see: $lcov_url
|
||||
END_OF_USAGE
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# check_and_load_module(module_name)
|
||||
#
|
||||
# Check whether a module by the given name is installed on this system
|
||||
# and make it known to the interpreter if available. Return undefined if it
|
||||
# is installed, an error message otherwise.
|
||||
#
|
||||
|
||||
sub check_and_load_module($)
|
||||
{
|
||||
eval("use $_[0];");
|
||||
return $@;
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# genpng_process_file(filename, out_filename, width, tab_size)
|
||||
#
|
||||
|
||||
sub genpng_process_file($$$$)
|
||||
{
|
||||
my $filename = $_[0];
|
||||
my $out_filename = $_[1];
|
||||
my $width = $_[2];
|
||||
my $tab_size = $_[3];
|
||||
local *HANDLE;
|
||||
my @source;
|
||||
|
||||
open(HANDLE, "<", $filename)
|
||||
or die("ERROR: cannot open $filename!\n");
|
||||
|
||||
# Check for .gcov filename extension
|
||||
if ($filename =~ /^(.*).gcov$/)
|
||||
{
|
||||
# Assume gcov text format
|
||||
while (<HANDLE>)
|
||||
{
|
||||
if (/^\t\t(.*)$/)
|
||||
{
|
||||
# Uninstrumented line
|
||||
push(@source, ":$1");
|
||||
}
|
||||
elsif (/^ ###### (.*)$/)
|
||||
{
|
||||
# Line with zero execution count
|
||||
push(@source, "0:$1");
|
||||
}
|
||||
elsif (/^( *)(\d*) (.*)$/)
|
||||
{
|
||||
# Line with positive execution count
|
||||
push(@source, "$2:$3");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# Plain text file
|
||||
while (<HANDLE>) { push(@source, ":$_"); }
|
||||
}
|
||||
close(HANDLE);
|
||||
|
||||
gen_png($out_filename, $width, $tab_size, @source);
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# gen_png(filename, width, tab_size, source)
|
||||
#
|
||||
# Write an overview PNG file to FILENAME. Source code is defined by SOURCE
|
||||
# which is a list of lines <count>:<source code> per source code line.
|
||||
# The output image will be made up of one pixel per character of source,
|
||||
# coloring will be done according to execution counts. WIDTH defines the
|
||||
# image width. TAB_SIZE specifies the number of spaces to use as replacement
|
||||
# string for tabulator signs in source code text.
|
||||
#
|
||||
# Die on error.
|
||||
#
|
||||
|
||||
sub gen_png($$$@)
|
||||
{
|
||||
my $filename = shift(@_); # Filename for PNG file
|
||||
my $overview_width = shift(@_); # Imagewidth for image
|
||||
my $tab_size = shift(@_); # Replacement string for tab signs
|
||||
my @source = @_; # Source code as passed via argument 2
|
||||
my $height; # Height as define by source size
|
||||
my $overview; # Source code overview image data
|
||||
my $col_plain_back; # Color for overview background
|
||||
my $col_plain_text; # Color for uninstrumented text
|
||||
my $col_cov_back; # Color for background of covered lines
|
||||
my $col_cov_text; # Color for text of covered lines
|
||||
my $col_nocov_back; # Color for background of lines which
|
||||
# were not covered (count == 0)
|
||||
my $col_nocov_text; # Color for test of lines which were not
|
||||
# covered (count == 0)
|
||||
my $col_hi_back; # Color for background of highlighted lines
|
||||
my $col_hi_text; # Color for text of highlighted lines
|
||||
my $line; # Current line during iteration
|
||||
my $row = 0; # Current row number during iteration
|
||||
my $column; # Current column number during iteration
|
||||
my $color_text; # Current text color during iteration
|
||||
my $color_back; # Current background color during iteration
|
||||
my $last_count; # Count of last processed line
|
||||
my $count; # Count of current line
|
||||
my $source; # Source code of current line
|
||||
my $replacement; # Replacement string for tabulator chars
|
||||
local *PNG_HANDLE; # Handle for output PNG file
|
||||
|
||||
# Handle empty source files
|
||||
if (!@source) {
|
||||
@source = ( "" );
|
||||
}
|
||||
$height = scalar(@source);
|
||||
# Create image
|
||||
$overview = new GD::Image($overview_width, $height)
|
||||
or die("ERROR: cannot allocate overview image!\n");
|
||||
|
||||
# Define colors
|
||||
$col_plain_back = $overview->colorAllocate(0xff, 0xff, 0xff);
|
||||
$col_plain_text = $overview->colorAllocate(0xaa, 0xaa, 0xaa);
|
||||
$col_cov_back = $overview->colorAllocate(0xaa, 0xa7, 0xef);
|
||||
$col_cov_text = $overview->colorAllocate(0x5d, 0x5d, 0xea);
|
||||
$col_nocov_back = $overview->colorAllocate(0xff, 0x00, 0x00);
|
||||
$col_nocov_text = $overview->colorAllocate(0xaa, 0x00, 0x00);
|
||||
$col_hi_back = $overview->colorAllocate(0x00, 0xff, 0x00);
|
||||
$col_hi_text = $overview->colorAllocate(0x00, 0xaa, 0x00);
|
||||
|
||||
# Visualize each line
|
||||
foreach $line (@source)
|
||||
{
|
||||
# Replace tabs with spaces to keep consistent with source
|
||||
# code view
|
||||
while ($line =~ /^([^\t]*)(\t)/)
|
||||
{
|
||||
$replacement = " "x($tab_size - ((length($1) - 1) %
|
||||
$tab_size));
|
||||
$line =~ s/^([^\t]*)(\t)/$1$replacement/;
|
||||
}
|
||||
|
||||
# Skip lines which do not follow the <count>:<line>
|
||||
# specification, otherwise $1 = count, $2 = source code
|
||||
if (!($line =~ /(\*?)(\d*):(.*)$/)) { next; }
|
||||
$count = $2;
|
||||
$source = $3;
|
||||
|
||||
# Decide which color pair to use
|
||||
|
||||
# If this line was not instrumented but the one before was,
|
||||
# take the color of that line to widen color areas in
|
||||
# resulting image
|
||||
if (($count eq "") && defined($last_count) &&
|
||||
($last_count ne ""))
|
||||
{
|
||||
$count = $last_count;
|
||||
}
|
||||
|
||||
if ($count eq "")
|
||||
{
|
||||
# Line was not instrumented
|
||||
$color_text = $col_plain_text;
|
||||
$color_back = $col_plain_back;
|
||||
}
|
||||
elsif ($count == 0)
|
||||
{
|
||||
# Line was instrumented but not executed
|
||||
$color_text = $col_nocov_text;
|
||||
$color_back = $col_nocov_back;
|
||||
}
|
||||
elsif ($1 eq "*")
|
||||
{
|
||||
# Line was highlighted
|
||||
$color_text = $col_hi_text;
|
||||
$color_back = $col_hi_back;
|
||||
}
|
||||
else
|
||||
{
|
||||
# Line was instrumented and executed
|
||||
$color_text = $col_cov_text;
|
||||
$color_back = $col_cov_back;
|
||||
}
|
||||
|
||||
# Write one pixel for each source character
|
||||
$column = 0;
|
||||
foreach (split("", $source))
|
||||
{
|
||||
# Check for width
|
||||
if ($column >= $overview_width) { last; }
|
||||
|
||||
if ($_ eq " ")
|
||||
{
|
||||
# Space
|
||||
$overview->setPixel($column++, $row,
|
||||
$color_back);
|
||||
}
|
||||
else
|
||||
{
|
||||
# Text
|
||||
$overview->setPixel($column++, $row,
|
||||
$color_text);
|
||||
}
|
||||
}
|
||||
|
||||
# Fill rest of line
|
||||
while ($column < $overview_width)
|
||||
{
|
||||
$overview->setPixel($column++, $row, $color_back);
|
||||
}
|
||||
|
||||
$last_count = $2;
|
||||
|
||||
$row++;
|
||||
}
|
||||
|
||||
# Write PNG file
|
||||
open (PNG_HANDLE, ">", $filename)
|
||||
or die("ERROR: cannot write png file $filename!\n");
|
||||
binmode(*PNG_HANDLE);
|
||||
print(PNG_HANDLE $overview->png());
|
||||
close(PNG_HANDLE);
|
||||
}
|
||||
|
||||
sub genpng_warn_handler($)
|
||||
{
|
||||
my ($msg) = @_;
|
||||
|
||||
warn("$tool_name: $msg");
|
||||
}
|
||||
|
||||
sub genpng_die_handler($)
|
||||
{
|
||||
my ($msg) = @_;
|
||||
|
||||
die("$tool_name: $msg");
|
||||
}
|
||||
+4448
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,66 @@
|
||||
// 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/algorithm.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (Algorithm, Clamp)
|
||||
{
|
||||
EXPECT_EQ (clamp (2.8, 1.4, 1.8), 1.8);
|
||||
EXPECT_EQ (clamp (1.2, 1.4, 1.8), 1.4);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (Algorithm, ClampNorm)
|
||||
{
|
||||
EXPECT_EQ (clampNorm (1.8), 1.);
|
||||
EXPECT_EQ (clampNorm (-0.1), 0.);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (Algorithm, NormalizedToSteps)
|
||||
{
|
||||
EXPECT_EQ (normalizedToSteps (0., 1), 0);
|
||||
EXPECT_EQ (normalizedToSteps (0.49, 1), 0);
|
||||
EXPECT_EQ (normalizedToSteps (0.50, 1), 1);
|
||||
EXPECT_EQ (normalizedToSteps (0.51, 1), 1);
|
||||
EXPECT_EQ (normalizedToSteps (1., 1), 1);
|
||||
|
||||
EXPECT_EQ (normalizedToSteps (0., 3), 0);
|
||||
EXPECT_EQ (normalizedToSteps (0.24, 3), 0);
|
||||
EXPECT_EQ (normalizedToSteps (0.25, 3), 1);
|
||||
EXPECT_EQ (normalizedToSteps (0.26, 3), 1);
|
||||
EXPECT_EQ (normalizedToSteps (0.49, 3), 1);
|
||||
EXPECT_EQ (normalizedToSteps (0.50, 3), 2);
|
||||
EXPECT_EQ (normalizedToSteps (0.51, 3), 2);
|
||||
EXPECT_EQ (normalizedToSteps (0.74, 3), 2);
|
||||
EXPECT_EQ (normalizedToSteps (0.75, 3), 3);
|
||||
EXPECT_EQ (normalizedToSteps (0.76, 3), 3);
|
||||
EXPECT_EQ (normalizedToSteps (1., 3), 3);
|
||||
|
||||
EXPECT_EQ (normalizedToSteps (0., 1, 1), 1);
|
||||
EXPECT_EQ (normalizedToSteps (0.5, 1, 1), 2);
|
||||
EXPECT_EQ (normalizedToSteps (1., 1, 1), 2);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (Agorithm, StepsToNormalized)
|
||||
{
|
||||
EXPECT_EQ (stepsToNormalized<double> (1, 1), 1.);
|
||||
EXPECT_EQ (stepsToNormalized<double> (0, 1), 0.);
|
||||
|
||||
EXPECT_EQ (stepsToNormalized<double> (0, 4), 0.);
|
||||
EXPECT_EQ (stepsToNormalized<double> (1, 4), 0.25);
|
||||
EXPECT_EQ (stepsToNormalized<double> (2, 4), 0.50);
|
||||
EXPECT_EQ (stepsToNormalized<double> (3, 4), 0.75);
|
||||
EXPECT_EQ (stepsToNormalized<double> (4, 4), 1.);
|
||||
|
||||
EXPECT_EQ (stepsToNormalized<double> (2, 1, 1), 1.);
|
||||
EXPECT_EQ (stepsToNormalized<double> (1, 1, 1), 0.);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+247
@@ -0,0 +1,247 @@
|
||||
// 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/animation/animations.h"
|
||||
#include "../../../../lib/controls/ccontrol.h"
|
||||
#include "../../../../lib/cview.h"
|
||||
#include "../../../../lib/cviewcontainer.h"
|
||||
#include "../../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
using namespace Animation;
|
||||
|
||||
namespace {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class TestView : public CView
|
||||
{
|
||||
public:
|
||||
TestView () : CView (CRect (0, 0, 0, 0)) {}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class TestControl : public CControl
|
||||
{
|
||||
public:
|
||||
TestControl () : CControl (CRect (0, 0, 0, 0)) {}
|
||||
void draw (CDrawContext* pContext) override {}
|
||||
|
||||
CLASS_METHODS (TestControl, CControl)
|
||||
};
|
||||
|
||||
} // anonymous
|
||||
|
||||
TEST_CASE (AlphaValueAnimtionTest, Animation)
|
||||
{
|
||||
TestView view;
|
||||
EXPECT (view.getAlphaValue () == 1.f);
|
||||
AlphaValueAnimation a (0.f);
|
||||
a.animationStart (&view, "");
|
||||
a.animationTick (&view, "", 0.5f);
|
||||
EXPECT (view.getAlphaValue () == 0.5f);
|
||||
a.animationTick (&view, "", 1.f);
|
||||
EXPECT (view.getAlphaValue () == 0.f);
|
||||
a.animationFinished (&view, "", false);
|
||||
EXPECT (view.getAlphaValue () == 0.f);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
TEST_CASE (ViewSizeAnimationTest, Animation)
|
||||
{
|
||||
TestView view;
|
||||
EXPECT (view.getViewSize () == CRect (0, 0, 0, 0));
|
||||
ViewSizeAnimation a (CRect (10, 10, 100, 100));
|
||||
a.animationStart (&view, "");
|
||||
a.animationTick (&view, "", 0.5f);
|
||||
EXPECT (view.getViewSize () == CRect (5, 5, 50, 50));
|
||||
a.animationTick (&view, "", 1.f);
|
||||
EXPECT (view.getViewSize () == CRect (10, 10, 100, 100));
|
||||
a.animationFinished (&view, "", false);
|
||||
EXPECT (view.getViewSize () == CRect (10, 10, 100, 100));
|
||||
}
|
||||
|
||||
TEST_CASE (ViewSizeAnimationTest, UnfinishedAnimation)
|
||||
{
|
||||
TestView view;
|
||||
ViewSizeAnimation a (CRect (10, 10, 100, 100));
|
||||
a.animationStart (&view, "");
|
||||
a.animationTick (&view, "", 0.5f);
|
||||
EXPECT (view.getViewSize () == CRect (5, 5, 50, 50));
|
||||
a.animationFinished (&view, "", false);
|
||||
EXPECT (view.getViewSize () == CRect (10, 10, 100, 100));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
TEST_CASE (ControlValueAnimationTest, Animation)
|
||||
{
|
||||
TestControl control;
|
||||
EXPECT (control.getValue () == 0.f);
|
||||
ControlValueAnimation a (1.f);
|
||||
a.animationStart (&control, "");
|
||||
EXPECT (control.getValue () == 0.f);
|
||||
a.animationTick (&control, "", 0.3f);
|
||||
EXPECT (control.getValue () == 0.3f);
|
||||
a.animationTick (&control, "", 0.5f);
|
||||
EXPECT (control.getValue () == 0.5f);
|
||||
a.animationFinished (&control, "", false);
|
||||
EXPECT (control.getValue () == 1.f);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
TEST_CASE (ExchangeViewAnimationTest, AlphaValueFade)
|
||||
{
|
||||
auto parentContainer = owned (new CViewContainer (CRect (0, 0, 0, 0)));
|
||||
auto container = new CViewContainer (CRect (0, 0, 0, 0));
|
||||
container->attached (parentContainer);
|
||||
auto oldView = new TestView ();
|
||||
auto newView = new TestView ();
|
||||
container->addView (oldView);
|
||||
ExchangeViewAnimation a (oldView, newView, ExchangeViewAnimation::kAlphaValueFade);
|
||||
a.animationStart (container, "");
|
||||
EXPECT (oldView->getAlphaValue () == 1.f);
|
||||
EXPECT (newView->getAlphaValue () == 0.f);
|
||||
a.animationTick (container, "", 0.5f);
|
||||
EXPECT (oldView->getAlphaValue () == 0.5f);
|
||||
EXPECT (newView->getAlphaValue () == 0.5f);
|
||||
a.animationTick (container, "", 1.f);
|
||||
a.animationFinished (container, "", false);
|
||||
EXPECT (oldView->isAttached () == false);
|
||||
EXPECT (newView->getAlphaValue () == 1.f);
|
||||
container->removed (parentContainer);
|
||||
}
|
||||
|
||||
TEST_CASE (ExchangeViewAnimationTest, PushInFromLeft)
|
||||
{
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto parentContainer = owned (new CViewContainer (r));
|
||||
auto container = new CViewContainer (r);
|
||||
container->attached (parentContainer);
|
||||
auto oldView = new CView (r);
|
||||
auto newView = new CView (r);
|
||||
container->addView (oldView);
|
||||
ExchangeViewAnimation a (oldView, newView, ExchangeViewAnimation::kPushInFromLeft);
|
||||
a.animationStart (container, "");
|
||||
EXPECT (oldView->getViewSize () == r);
|
||||
EXPECT (newView->getViewSize () == CRect (-100, 0, 0, 100));
|
||||
a.animationTick (container, "", 0.5f);
|
||||
EXPECT (newView->getViewSize () == CRect (-50, 0, 50, 100));
|
||||
a.animationTick (container, "", 1.f);
|
||||
a.animationFinished (container, "", false);
|
||||
EXPECT (oldView->isAttached () == false);
|
||||
EXPECT (newView->getViewSize () == r);
|
||||
container->removed (parentContainer);
|
||||
}
|
||||
|
||||
TEST_CASE (ExchangeViewAnimationTest, PushInFromRight)
|
||||
{
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto parentContainer = owned (new CViewContainer (r));
|
||||
auto container = new CViewContainer (r);
|
||||
container->attached (parentContainer);
|
||||
auto oldView = new CView (r);
|
||||
auto newView = new CView (r);
|
||||
container->addView (oldView);
|
||||
ExchangeViewAnimation a (oldView, newView, ExchangeViewAnimation::kPushInFromRight);
|
||||
a.animationStart (container, "");
|
||||
EXPECT (oldView->getViewSize () == r);
|
||||
EXPECT (newView->getViewSize () == CRect (100, 0, 200, 100));
|
||||
a.animationTick (container, "", 0.5f);
|
||||
EXPECT (newView->getViewSize () == CRect (50, 0, 150, 100));
|
||||
a.animationTick (container, "", 1.f);
|
||||
a.animationFinished (container, "", false);
|
||||
EXPECT (oldView->isAttached () == false);
|
||||
EXPECT (newView->getViewSize () == r);
|
||||
container->removed (parentContainer);
|
||||
}
|
||||
|
||||
TEST_CASE (ExchangeViewAnimationTest, PushInFromTop)
|
||||
{
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto parentContainer = owned (new CViewContainer (r));
|
||||
auto container = new CViewContainer (r);
|
||||
container->attached (parentContainer);
|
||||
auto oldView = new CView (r);
|
||||
auto newView = new CView (r);
|
||||
container->addView (oldView);
|
||||
ExchangeViewAnimation a (oldView, newView, ExchangeViewAnimation::kPushInFromTop);
|
||||
a.animationStart (container, "");
|
||||
EXPECT (oldView->getViewSize () == r);
|
||||
EXPECT (newView->getViewSize () == CRect (0, -100, 100, 0));
|
||||
a.animationTick (container, "", 0.5f);
|
||||
EXPECT (newView->getViewSize () == CRect (0, -50, 100, 50));
|
||||
a.animationTick (container, "", 1.f);
|
||||
a.animationFinished (container, "", false);
|
||||
EXPECT (oldView->isAttached () == false);
|
||||
EXPECT (newView->getViewSize () == r);
|
||||
container->removed (parentContainer);
|
||||
}
|
||||
|
||||
TEST_CASE (ExchangeViewAnimationTest, PushInFromBottom)
|
||||
{
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto parentContainer = owned (new CViewContainer (r));
|
||||
auto container = new CViewContainer (r);
|
||||
container->attached (parentContainer);
|
||||
auto oldView = new CView (r);
|
||||
auto newView = new CView (r);
|
||||
container->addView (oldView);
|
||||
ExchangeViewAnimation a (oldView, newView, ExchangeViewAnimation::kPushInFromBottom);
|
||||
a.animationStart (container, "");
|
||||
EXPECT (oldView->getViewSize () == r);
|
||||
EXPECT (newView->getViewSize () == CRect (0, 100, 100, 200));
|
||||
a.animationTick (container, "", 0.5f);
|
||||
EXPECT (newView->getViewSize () == CRect (0, 50, 100, 150));
|
||||
a.animationTick (container, "", 1.f);
|
||||
a.animationFinished (container, "", false);
|
||||
EXPECT (oldView->isAttached () == false);
|
||||
EXPECT (newView->getViewSize () == r);
|
||||
container->removed (parentContainer);
|
||||
}
|
||||
|
||||
TEST_CASE (ExchangeViewAnimationTest, PushInOutFromLeft)
|
||||
{
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto parentContainer = owned (new CViewContainer (r));
|
||||
auto container = new CViewContainer (r);
|
||||
container->attached (parentContainer);
|
||||
auto oldView = new CView (r);
|
||||
auto newView = new CView (r);
|
||||
container->addView (oldView);
|
||||
ExchangeViewAnimation a (oldView, newView, ExchangeViewAnimation::kPushInOutFromLeft);
|
||||
a.animationStart (container, "");
|
||||
EXPECT (oldView->getViewSize () == r);
|
||||
EXPECT (newView->getViewSize () == CRect (-100, 0, 0, 100));
|
||||
a.animationTick (container, "", 0.5f);
|
||||
EXPECT (oldView->getViewSize () == CRect (50, 0, 150, 100));
|
||||
EXPECT (newView->getViewSize () == CRect (-50, 0, 50, 100));
|
||||
a.animationTick (container, "", 1.f);
|
||||
a.animationFinished (container, "", false);
|
||||
EXPECT (oldView->isAttached () == false);
|
||||
EXPECT (newView->getViewSize () == r);
|
||||
container->removed (parentContainer);
|
||||
}
|
||||
|
||||
TEST_CASE (ExchangeViewAnimationTest, PushInOutFromRight)
|
||||
{
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto parentContainer = owned (new CViewContainer (r));
|
||||
auto container = new CViewContainer (r);
|
||||
container->attached (parentContainer);
|
||||
auto oldView = new CView (r);
|
||||
auto newView = new CView (r);
|
||||
container->addView (oldView);
|
||||
ExchangeViewAnimation a (oldView, newView, ExchangeViewAnimation::kPushInOutFromRight);
|
||||
a.animationStart (container, "");
|
||||
EXPECT (oldView->getViewSize () == r);
|
||||
EXPECT (newView->getViewSize () == CRect (100, 0, 200, 100));
|
||||
a.animationTick (container, "", 0.5f);
|
||||
EXPECT (oldView->getViewSize () == CRect (-50, 0, 50, 100));
|
||||
EXPECT (newView->getViewSize () == CRect (50, 0, 150, 100));
|
||||
a.animationFinished (container, "", true);
|
||||
EXPECT (oldView->isAttached () == false);
|
||||
EXPECT (newView->getViewSize () == r);
|
||||
container->removed (parentContainer);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+120
@@ -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/animation/animations.h"
|
||||
#include "../../../../lib/animation/animator.h"
|
||||
#include "../../../../lib/animation/timingfunctions.h"
|
||||
#include "../../../../lib/cview.h"
|
||||
#include "../../unittests.h"
|
||||
|
||||
#if MAC
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
namespace VSTGUI {
|
||||
using namespace Animation;
|
||||
|
||||
namespace {
|
||||
|
||||
struct RemoveAnimationInCallback : public IAnimationTarget
|
||||
{
|
||||
RemoveAnimationInCallback (Animator* animator) : animator (animator) {}
|
||||
|
||||
Animator* animator;
|
||||
|
||||
void animationStart (CView* view, IdStringPtr name) override {}
|
||||
void animationTick (CView* view, IdStringPtr name, float pos) override
|
||||
{
|
||||
animator->removeAnimations (view);
|
||||
}
|
||||
void animationFinished (CView* view, IdStringPtr name, bool wasCanceled) override {}
|
||||
};
|
||||
|
||||
} // anonymous
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
TEST_CASE (AnimatorTest, AddAnimation)
|
||||
{
|
||||
auto a = owned (new Animator ());
|
||||
auto view = owned (new CView (CRect (0, 0, 0, 0)));
|
||||
a->addAnimation (view, "Test", new AlphaValueAnimation (0.f), new LinearTimingFunction (100),
|
||||
[] (CView*, const IdStringPtr, IAnimationTarget*) {
|
||||
CFRunLoopStop (CFRunLoopGetCurrent ());
|
||||
});
|
||||
CFRunLoopRun ();
|
||||
EXPECT (view->getAlphaValue () == 0.f);
|
||||
}
|
||||
|
||||
TEST_CASE (AnimatorTest, CancelAnimation)
|
||||
{
|
||||
auto a = owned (new Animator ());
|
||||
auto view = owned (new CView (CRect (0, 0, 0, 0)));
|
||||
a->addAnimation (view, "Test", new AlphaValueAnimation (0.f), new LinearTimingFunction (2000));
|
||||
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.2, false);
|
||||
a->removeAnimation (view, "Test");
|
||||
EXPECT (view->getAlphaValue () != 0.f);
|
||||
}
|
||||
|
||||
TEST_CASE (AnimatorTest, CancelAnimationWithCallback)
|
||||
{
|
||||
auto a = owned (new Animator ());
|
||||
auto view = owned (new CView (CRect (0, 0, 0, 0)));
|
||||
bool cancelDoneFunctionCalled = false;
|
||||
auto doneFunc = [&] (auto, auto, auto) { cancelDoneFunctionCalled = true; };
|
||||
a->addAnimation (view, "Test", new AlphaValueAnimation (0.f), new LinearTimingFunction (2000),
|
||||
doneFunc, false);
|
||||
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.2, false);
|
||||
a->removeAnimation (view, "Test");
|
||||
EXPECT_FALSE (cancelDoneFunctionCalled);
|
||||
EXPECT (view->getAlphaValue () != 0.f);
|
||||
a->addAnimation (view, "Test", new AlphaValueAnimation (0.f), new LinearTimingFunction (2000),
|
||||
doneFunc, true);
|
||||
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.2, false);
|
||||
a->removeAnimation (view, "Test");
|
||||
EXPECT_TRUE (cancelDoneFunctionCalled);
|
||||
}
|
||||
|
||||
TEST_CASE (AnimatorTest, RemoveAnimationInCallback)
|
||||
{
|
||||
auto a = owned (new Animator ());
|
||||
auto view = owned (new CView (CRect (0, 0, 0, 0)));
|
||||
a->addAnimation (view, "Test", new RemoveAnimationInCallback (a),
|
||||
new LinearTimingFunction (100),
|
||||
[] (CView*, const IdStringPtr, IAnimationTarget*) {
|
||||
CFRunLoopStop (CFRunLoopGetCurrent ());
|
||||
});
|
||||
CFRunLoopRun ();
|
||||
}
|
||||
|
||||
#if VSTGUI_ENABLE_DEPRECATED_METHODS
|
||||
#include "../../../../lib/private/disabledeprecatedmessage.h"
|
||||
|
||||
struct MessageReceiver : public CBaseObject
|
||||
{
|
||||
CMessageResult notify (CBaseObject* sender, IdStringPtr message) override
|
||||
{
|
||||
messageReceived = true;
|
||||
CFRunLoopStop (CFRunLoopGetCurrent ());
|
||||
return kMessageNotified;
|
||||
}
|
||||
|
||||
bool messageReceived {false};
|
||||
};
|
||||
|
||||
TEST_CASE (AnimatorTest, AnimationMessage)
|
||||
{
|
||||
auto a = owned (new Animator ());
|
||||
auto view = owned (new CView (CRect (0, 0, 0, 0)));
|
||||
MessageReceiver recevier;
|
||||
a->addAnimation (view, "Test", new AlphaValueAnimation (0.f), new LinearTimingFunction (100),
|
||||
&recevier);
|
||||
CFRunLoopRun ();
|
||||
EXPECT (recevier.messageReceived == true)
|
||||
}
|
||||
#include "../../../../lib/private/enabledeprecatedmessage.h"
|
||||
#endif
|
||||
|
||||
} // VSTGUI
|
||||
|
||||
#endif // MAC
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
// 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/animation/timingfunctions.h"
|
||||
#include "../../../../lib/controls/ccontrol.h"
|
||||
#include "../../../../lib/cview.h"
|
||||
#include "../../../../lib/cviewcontainer.h"
|
||||
#include "../../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
using namespace Animation;
|
||||
|
||||
TEST_CASE (TimingFunctionTest, LinearTimingFunction)
|
||||
{
|
||||
LinearTimingFunction f (100);
|
||||
ITimingFunction& tf = dynamic_cast<ITimingFunction&> (f);
|
||||
EXPECT (tf.getPosition (0) == 0.f);
|
||||
EXPECT (tf.getPosition (50) == 0.5f);
|
||||
EXPECT (tf.getPosition (100) == 1.f);
|
||||
EXPECT (tf.getPosition (150) == 1.f);
|
||||
}
|
||||
|
||||
TEST_CASE (TimingFunctionTest, PowerTwoTimingFunction)
|
||||
{
|
||||
PowerTimingFunction f (100, 2);
|
||||
ITimingFunction& tf = dynamic_cast<ITimingFunction&> (f);
|
||||
EXPECT (tf.getPosition (0) == 0.f);
|
||||
EXPECT (tf.getPosition (50) == 0.25f);
|
||||
EXPECT (tf.getPosition (86) == 0.7396f);
|
||||
EXPECT (tf.getPosition (100) == 1.f);
|
||||
EXPECT (tf.getPosition (150) == 1.f);
|
||||
}
|
||||
|
||||
TEST_CASE (TimingFunctionTest, PowerFourTimingFunction)
|
||||
{
|
||||
PowerTimingFunction f (100, 4);
|
||||
ITimingFunction& tf = dynamic_cast<ITimingFunction&> (f);
|
||||
EXPECT (tf.getPosition (0) == 0.f);
|
||||
EXPECT (tf.getPosition (50) == 0.0625f);
|
||||
EXPECT (tf.getPosition (100) == 1.f);
|
||||
EXPECT (tf.getPosition (150) == 1.f);
|
||||
}
|
||||
|
||||
TEST_CASE (TimingFunctionTest, InterpolationTimingFunction)
|
||||
{
|
||||
InterpolationTimingFunction f (100);
|
||||
f.addPoint (0.5, 0.4f);
|
||||
ITimingFunction& tf = dynamic_cast<ITimingFunction&> (f);
|
||||
EXPECT (tf.getPosition (0) == 0.f);
|
||||
EXPECT (tf.getPosition (25) == 0.2f);
|
||||
EXPECT (tf.getPosition (50) == 0.4f);
|
||||
EXPECT (tf.getPosition (75) == 0.7f);
|
||||
EXPECT (tf.getPosition (100) == 1.f);
|
||||
EXPECT (tf.getPosition (150) == 1.f);
|
||||
}
|
||||
|
||||
TEST_CASE (TimingFunctionTest, RepeatTimingFunction)
|
||||
{
|
||||
auto lf = new LinearTimingFunction (100);
|
||||
RepeatTimingFunction f (lf, 2, false);
|
||||
ITimingFunction& tf = dynamic_cast<ITimingFunction&> (f);
|
||||
EXPECT (tf.getPosition (0) == 0.f);
|
||||
EXPECT (tf.getPosition (50) == 0.5f);
|
||||
EXPECT (tf.getPosition (100) == 1.f);
|
||||
EXPECT (tf.isDone (100) == false);
|
||||
EXPECT (tf.getPosition (110) == 0.1f);
|
||||
EXPECT (tf.getPosition (150) == 0.5f);
|
||||
EXPECT (tf.getPosition (200) == 1.0f);
|
||||
EXPECT (tf.isDone (200) == true);
|
||||
}
|
||||
|
||||
TEST_CASE (TimingFunctionTest, RepeatTimingFunctionReverse)
|
||||
{
|
||||
auto lf = new LinearTimingFunction (100);
|
||||
RepeatTimingFunction f (lf, 2, true);
|
||||
ITimingFunction& tf = dynamic_cast<ITimingFunction&> (f);
|
||||
EXPECT (tf.getPosition (0) == 0.f);
|
||||
EXPECT (tf.getPosition (50) == 0.5f);
|
||||
EXPECT (tf.getPosition (100) == 1.f);
|
||||
EXPECT (tf.isDone (100) == false);
|
||||
EXPECT (tf.getPosition (110) == 0.9f);
|
||||
EXPECT (tf.getPosition (150) == 0.5f);
|
||||
EXPECT (tf.getPosition (200) == 0.f);
|
||||
EXPECT (tf.isDone (200) == true);
|
||||
}
|
||||
|
||||
TEST_CASE (TimingFunctionTest, CubicBezierTimingFunction)
|
||||
{
|
||||
CubicBezierTimingFunction f (100, CPoint (0.42, 0.), CPoint (0.58, 1.));
|
||||
EXPECT (f.getPosition (0) == 0.f);
|
||||
EXPECT (f.getPosition (25) < 0.25f);
|
||||
EXPECT (f.getPosition (50) == 0.5f);
|
||||
EXPECT (f.getPosition (75) > 0.75f);
|
||||
EXPECT (f.getPosition (100) == 1.0f);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,201 @@
|
||||
// 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/platform/iplatformbitmap.h"
|
||||
#include "../../../lib/platform/platformfactory.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (CBitmap, ScaleFactor)
|
||||
{
|
||||
CPoint p (10, 10);
|
||||
auto b1 = getPlatformFactory ().createBitmap (p);
|
||||
CBitmap bitmap (b1);
|
||||
p (20, 20);
|
||||
auto b2 = getPlatformFactory ().createBitmap (p);
|
||||
b2->setScaleFactor (2.);
|
||||
EXPECT_TRUE (bitmap.addBitmap (b2));
|
||||
|
||||
p (21, 21);
|
||||
auto b3 = getPlatformFactory ().createBitmap (p);
|
||||
EXPECT_EXCEPTION (bitmap.addBitmap (b3), "wrong bitmap size");
|
||||
|
||||
EXPECT_EQ (bitmap.getBestPlatformBitmapForScaleFactor (0.5), b1);
|
||||
EXPECT_EQ (bitmap.getBestPlatformBitmapForScaleFactor (1.0), b1);
|
||||
EXPECT_EQ (bitmap.getBestPlatformBitmapForScaleFactor (1.4), b1);
|
||||
EXPECT_EQ (bitmap.getBestPlatformBitmapForScaleFactor (1.5), b2);
|
||||
EXPECT_EQ (bitmap.getBestPlatformBitmapForScaleFactor (1.6), b2);
|
||||
EXPECT_EQ (bitmap.getBestPlatformBitmapForScaleFactor (2.6), b2);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (CBitmap, PixelAccess)
|
||||
{
|
||||
CBitmap bitmap (10, 10);
|
||||
EXPECT_EQ (bitmap.getWidth (), 10);
|
||||
EXPECT_EQ (bitmap.getHeight (), 10);
|
||||
|
||||
auto accessor = owned (CBitmapPixelAccess::create (&bitmap));
|
||||
EXPECT (accessor);
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
CColor color;
|
||||
do
|
||||
{
|
||||
accessor->getColor (color);
|
||||
EXPECT_EQ (color, CColor (0, 0, 0, 0));
|
||||
accessor->setColor (kRedCColor);
|
||||
accessor->getColor (color);
|
||||
EXPECT_EQ (color, kRedCColor);
|
||||
accessor->setColor (kGreenCColor);
|
||||
accessor->getColor (color);
|
||||
EXPECT_EQ (color, kGreenCColor);
|
||||
accessor->setColor (kBlueCColor);
|
||||
accessor->getColor (color);
|
||||
EXPECT_EQ (color, kBlueCColor);
|
||||
EXPECT_EQ (accessor->getX (), x);
|
||||
EXPECT_EQ (accessor->getY (), y);
|
||||
if (++x == accessor->getBitmapWidth ())
|
||||
{
|
||||
++y;
|
||||
x = 0;
|
||||
}
|
||||
} while (++(*accessor));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (CBitmap, PixelAccess2)
|
||||
{
|
||||
CBitmap bitmap (10, 10);
|
||||
CColor color (255, 1, 2, 150);
|
||||
if (auto accessor = owned (CBitmapPixelAccess::create (&bitmap)))
|
||||
{
|
||||
do
|
||||
{
|
||||
accessor->setColor (color);
|
||||
} while (++(*accessor));
|
||||
}
|
||||
if (auto accessor = owned (CBitmapPixelAccess::create (&bitmap)))
|
||||
{
|
||||
do
|
||||
{
|
||||
CColor c;
|
||||
accessor->getColor (c);
|
||||
EXPECT_EQ (c, color);
|
||||
} while (++(*accessor));
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (CMultiFrameBitmap, NotInitialized)
|
||||
{
|
||||
CMultiFrameBitmap bitmap (100, 100);
|
||||
auto fr = bitmap.calcFrameRect (0);
|
||||
EXPECT_EQ (fr, CRect (0, 0, 100, 100));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (CMultiFrameBitmap, CalcFrameRect)
|
||||
{
|
||||
CMultiFrameBitmap bitmap (100, 100);
|
||||
EXPECT_TRUE (bitmap.setMultiFrameDesc ({{50, 50}, 4, 2}));
|
||||
EXPECT_EQ (bitmap.getFrameSize (), CPoint (50., 50.));
|
||||
EXPECT_EQ (bitmap.getNumFrames (), 4);
|
||||
EXPECT_EQ (bitmap.getNumFramesPerRow (), 2);
|
||||
EXPECT_EQ (bitmap.calcFrameRect (0), CRect (0, 0, 50, 50));
|
||||
EXPECT_EQ (bitmap.calcFrameRect (1), CRect (50, 0, 100, 50));
|
||||
EXPECT_EQ (bitmap.calcFrameRect (2), CRect (0, 50, 50, 100));
|
||||
EXPECT_EQ (bitmap.calcFrameRect (3), CRect (50, 50, 100, 100));
|
||||
EXPECT_EQ (bitmap.calcFrameRect (4), CRect (50, 50, 100, 100));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (CMultiFrameBitmap, InvalidFrameDesc)
|
||||
{
|
||||
CMultiFrameBitmap bitmap (100, 100);
|
||||
EXPECT_FALSE (bitmap.setMultiFrameDesc ({{50, 50}, 4, 1}));
|
||||
EXPECT_FALSE (bitmap.setMultiFrameDesc ({{50, 50}, 4, 4}));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------
|
||||
struct MultiFrameBitmapViewTest : MultiFrameBitmapView<MultiFrameBitmapViewTest>
|
||||
{
|
||||
void invalid () {}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (MultiFrameBitmapViewTest, Default)
|
||||
{
|
||||
MultiFrameBitmapViewTest testView;
|
||||
CMultiFrameBitmap bitmap (100, 100);
|
||||
EXPECT_TRUE (bitmap.setMultiFrameDesc ({{50, 50}, 4, 2}));
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 0.f), 0);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 0.33f), 1);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 0.66f), 2);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 1.f), 3);
|
||||
EXPECT_EQ (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 0), 0.f);
|
||||
EXPECT_EQ (
|
||||
static_cast<int> (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 1) * 100.f), 33);
|
||||
EXPECT_EQ (
|
||||
static_cast<int> (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 2) * 100.f), 66);
|
||||
EXPECT_EQ (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 3), 1.f);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (MultiFrameBitmapViewTest, Range)
|
||||
{
|
||||
MultiFrameBitmapViewTest testView;
|
||||
CMultiFrameBitmap bitmap (100, 100);
|
||||
EXPECT_TRUE (bitmap.setMultiFrameDesc ({{50, 50}, 4, 2}));
|
||||
testView.setMultiFrameBitmapRange (0, 1);
|
||||
auto range = testView.getMultiFrameBitmapRange ();
|
||||
EXPECT_EQ (range.first, 0);
|
||||
EXPECT_EQ (range.second, 1);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 0.f), 0);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 1.f), 1);
|
||||
EXPECT_EQ (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 0), 0.f);
|
||||
EXPECT_EQ (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 1), 1.f);
|
||||
|
||||
testView.setMultiFrameBitmapRange (2, -1);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 0.f), 2);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 1.f), 3);
|
||||
EXPECT_EQ (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 2), 0.f);
|
||||
EXPECT_EQ (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 3), 1.f);
|
||||
|
||||
testView.setMultiFrameBitmapRange (2, 3);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 0.f), 2);
|
||||
EXPECT_EQ (testView.getMultiFrameBitmapIndex (bitmap, 1.f), 3);
|
||||
EXPECT_EQ (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 2), 0.f);
|
||||
EXPECT_EQ (testView.getNormValueFromMultiFrameBitmapIndex (bitmap, 3), 1.f);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (MultiFrameBitmapViewTest, Inverse)
|
||||
{
|
||||
MultiFrameBitmapViewTest testView;
|
||||
CMultiFrameBitmap bitmap (100, 100);
|
||||
EXPECT_TRUE (bitmap.setMultiFrameDesc ({{50, 50}, 4, 2}));
|
||||
testView.setMultiFrameBitmapRange (0, 1);
|
||||
EXPECT_EQ (testView.getInverseIndex (bitmap, 0), 1);
|
||||
EXPECT_EQ (testView.getInverseIndex (bitmap, 1), 0);
|
||||
|
||||
testView.setMultiFrameBitmapRange (2, -1);
|
||||
EXPECT_EQ (testView.getInverseIndex (bitmap, 2), 3);
|
||||
EXPECT_EQ (testView.getInverseIndex (bitmap, 3), 2);
|
||||
|
||||
testView.setMultiFrameBitmapRange (2, 3);
|
||||
EXPECT_EQ (testView.getInverseIndex (bitmap, 2), 3);
|
||||
EXPECT_EQ (testView.getInverseIndex (bitmap, 3), 2);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // VSTGUI
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// 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"
|
||||
#include "../../../lib/cbuttonstate.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CButtonStateTests, Test)
|
||||
{
|
||||
CButtonState s;
|
||||
EXPECT_EQ (s.getButtonState (), 0);
|
||||
EXPECT_EQ (s.getModifierState (), 0);
|
||||
s = kLButton;
|
||||
EXPECT_TRUE (s.isLeftButton ());
|
||||
s |= kShift;
|
||||
EXPECT_TRUE (s.isLeftButton ());
|
||||
EXPECT_EQ (s.getModifierState (), kShift);
|
||||
s = kRButton;
|
||||
EXPECT_TRUE (s.isRightButton ());
|
||||
s |= kDoubleClick;
|
||||
EXPECT_TRUE (s.isDoubleClick ());
|
||||
EXPECT (s & CButtonState (kDoubleClick));
|
||||
CButtonState s2 (s);
|
||||
EXPECT_EQ (s, s2);
|
||||
s2 = ~s;
|
||||
EXPECT_NE (s, s2);
|
||||
}
|
||||
|
||||
} // 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/cclipboard.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
#if !WINDOWS
|
||||
// the OLE clipboard functionality returns Ole not initialized even tho we call OleInitialize()
|
||||
// so we disable the test for now on Windows
|
||||
|
||||
TEST_CASE (CClipboardTest, String)
|
||||
{
|
||||
EXPECT_TRUE (CClipboard::setString ("This is a test string"));
|
||||
auto cbStr = CClipboard::getString ();
|
||||
EXPECT_TRUE (cbStr);
|
||||
EXPECT (*cbStr == "This is a test string");
|
||||
}
|
||||
|
||||
TEST_CASE (CClipboardTest, FilePath)
|
||||
{
|
||||
#if WINDOWS
|
||||
constexpr auto path = "C:\\Windows\\test.txt";
|
||||
#else
|
||||
constexpr auto path = "/tmp/test.txt";
|
||||
#endif
|
||||
EXPECT_TRUE (CClipboard::setFilePath (path));
|
||||
auto cbStr = CClipboard::getFilePath ();
|
||||
EXPECT_TRUE (cbStr);
|
||||
EXPECT (*cbStr == path);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,181 @@
|
||||
// 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/ccolor.h"
|
||||
#include "../../../lib/cstring.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
TEST_CASE (CColorTest, MakeCColor)
|
||||
{
|
||||
CColor c = MakeCColor (10, 20, 30, 40);
|
||||
EXPECT_EQ (c.red, 10);
|
||||
EXPECT_EQ (c.green, 20);
|
||||
EXPECT_EQ (c.blue, 30);
|
||||
EXPECT_EQ (c.alpha, 40);
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, Luma)
|
||||
{
|
||||
CColor c (30, 50, 80, 255);
|
||||
EXPECT_EQ (c.getLuma (), 47);
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, Lightness)
|
||||
{
|
||||
CColor c (80, 30, 50, 255);
|
||||
EXPECT_EQ (c.getLightness (), 55);
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, OperatorEqual)
|
||||
{
|
||||
CColor c (30, 40, 50, 60);
|
||||
EXPECT_TRUE (c == CColor (30, 40, 50, 60));
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, OperatorNotEqual)
|
||||
{
|
||||
CColor c (30, 40, 50, 60);
|
||||
EXPECT (c != CColor (50, 40, 50, 60));
|
||||
EXPECT (c != CColor (30, 50, 50, 60));
|
||||
EXPECT (c != CColor (30, 40, 60, 60));
|
||||
EXPECT (c != CColor (30, 40, 50, 70));
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, CopyConstructor)
|
||||
{
|
||||
CColor c (60, 50, 40, 100);
|
||||
CColor c2 (c);
|
||||
EXPECT_EQ (c, c2);
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, AssignOperator)
|
||||
{
|
||||
CColor c;
|
||||
c (20, 30, 40, 50);
|
||||
EXPECT_EQ (c, CColor (20, 30, 40, 50));
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
static constexpr auto advanceCount = 16;
|
||||
#else
|
||||
static constexpr auto advanceCount = 1;
|
||||
#endif
|
||||
|
||||
TEST_CASE (CColorTest, HSV)
|
||||
{
|
||||
double hue;
|
||||
double saturation;
|
||||
double value;
|
||||
for (uint16_t red = 0; red <= 255; red += advanceCount)
|
||||
{
|
||||
for (uint16_t green = 0; green <= 255; green += advanceCount)
|
||||
{
|
||||
for (uint16_t blue = 0; blue <= 255; blue += advanceCount)
|
||||
{
|
||||
CColor c (static_cast<uint8_t> (red), static_cast<uint8_t> (green),
|
||||
static_cast<uint8_t> (blue));
|
||||
c.toHSV (hue, saturation, value);
|
||||
c.fromHSV (hue, saturation, value);
|
||||
EXPECT_EQ (c.red, red)
|
||||
EXPECT_EQ (c.green, green)
|
||||
EXPECT_EQ (c.blue, blue)
|
||||
EXPECT_EQ (c.alpha, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, HSL)
|
||||
{
|
||||
double hue;
|
||||
double saturation;
|
||||
double lightness;
|
||||
for (uint16_t red = 0; red <= 255; red += advanceCount)
|
||||
{
|
||||
for (uint16_t green = 0; green <= 255; green += advanceCount)
|
||||
{
|
||||
for (uint16_t blue = 0; blue <= 255; blue += advanceCount)
|
||||
{
|
||||
CColor c (static_cast<uint8_t> (red), static_cast<uint8_t> (green),
|
||||
static_cast<uint8_t> (blue));
|
||||
c.toHSL (hue, saturation, lightness);
|
||||
c.fromHSL (hue, saturation, lightness);
|
||||
EXPECT_EQ (c.red, red)
|
||||
EXPECT_EQ (c.green, green)
|
||||
EXPECT_EQ (c.blue, blue)
|
||||
EXPECT_EQ (c.alpha, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, IsColorRepresentation)
|
||||
{
|
||||
EXPECT_TRUE (CColor::isColorRepresentation ("#FF00FFFF"sv));
|
||||
// EXPECT_FALSE (CColor::isColorRepresentation ("#ABCDEFGH"));
|
||||
EXPECT_FALSE (CColor::isColorRepresentation ("star"sv));
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, ToString)
|
||||
{
|
||||
auto str = CColor (255, 255, 255).toString ();
|
||||
EXPECT_EQ (str, "#ffffffff")
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, FromString)
|
||||
{
|
||||
CColor c;
|
||||
EXPECT_TRUE (c.fromString ("#FFFFFFFF"sv));
|
||||
EXPECT_EQ (c, CColor (255, 255, 255));
|
||||
c.fromString ("#FF0000FF"sv);
|
||||
EXPECT_EQ (c, CColor (255, 0, 0));
|
||||
c.fromString ("#00FF00FF"sv);
|
||||
EXPECT_EQ (c, CColor (0, 255, 0));
|
||||
c.fromString ("#0000FFFF"sv);
|
||||
EXPECT_EQ (c, CColor (0, 0, 255));
|
||||
c.fromString ("#0000FF00"sv);
|
||||
EXPECT_EQ (c, CColor (0, 0, 255, 0));
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, SetNormalized)
|
||||
{
|
||||
CColor c (0, 0, 0, 0);
|
||||
c.setNormRed (1.);
|
||||
c.setNormGreen (1.);
|
||||
c.setNormBlue (1.);
|
||||
c.setNormAlpha (1.);
|
||||
EXPECT_EQ (c.red, 255);
|
||||
EXPECT_EQ (c.green, 255);
|
||||
EXPECT_EQ (c.blue, 255);
|
||||
EXPECT_EQ (c.alpha, 255);
|
||||
c.setNormRed (0.5);
|
||||
c.setNormGreen (0.5);
|
||||
c.setNormBlue (0.5);
|
||||
c.setNormAlpha (0.5);
|
||||
EXPECT_EQ (c.red, 128);
|
||||
EXPECT_EQ (c.green, 128);
|
||||
EXPECT_EQ (c.blue, 128);
|
||||
EXPECT_EQ (c.alpha, 128);
|
||||
}
|
||||
|
||||
TEST_CASE (CColorTest, GetNormalized)
|
||||
{
|
||||
CColor r (kRedCColor);
|
||||
EXPECT_EQ (r.normRed<double> (), 1.);
|
||||
EXPECT_EQ (r.normGreen<double> (), 0.);
|
||||
EXPECT_EQ (r.normBlue<double> (), 0.);
|
||||
EXPECT_EQ (r.normAlpha<double> (), 1.);
|
||||
r.green = 127;
|
||||
EXPECT_EQ (r.normGreen<double> (), 127. / 255.);
|
||||
r.blue = 33;
|
||||
EXPECT_EQ (r.normBlue<double> (), 33. / 255.);
|
||||
r.alpha = 250;
|
||||
EXPECT_EQ (r.normAlpha<double> (), 250. / 255.);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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"
|
||||
#include "../../../lib/cfont.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TESTCASE(CFontTests,
|
||||
|
||||
TEST(attributes,
|
||||
CFontDesc f;
|
||||
EXPECT(f.getName ().empty ());
|
||||
EXPECT(f.getSize () == 0.);
|
||||
EXPECT(f.getStyle () == kNormalFace);
|
||||
f.setName ("Test");
|
||||
EXPECT(strcmp (f.getName (), "Test") == 0);
|
||||
f.setSize (20.2);
|
||||
EXPECT(f.getSize () == 20.2);
|
||||
f.setStyle (kBoldFace|kItalicFace);
|
||||
EXPECT(f.getStyle () == (kBoldFace|kItalicFace));
|
||||
CFontDesc::cleanup ();
|
||||
);
|
||||
|
||||
TEST(copyConstructor,
|
||||
CFontDesc f (*kSystemFont);
|
||||
EXPECT(f == *kSystemFont);
|
||||
);
|
||||
|
||||
TEST(notEqualOperator,
|
||||
CFontDesc f (*kSystemFont);
|
||||
EXPECT(f == *kSystemFont);
|
||||
f.setSize (f.getSize ()+1);
|
||||
EXPECT(f != *kSystemFont);
|
||||
f = *kSystemFont;
|
||||
f.setStyle (kBoldFace);
|
||||
EXPECT(f != *kSystemFont);
|
||||
f = *kSystemFont;
|
||||
f.setName ("Bla");
|
||||
EXPECT(f != *kSystemFont);
|
||||
);
|
||||
|
||||
);
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,736 @@
|
||||
// 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/ccolor.h"
|
||||
#include "../../../lib/cframe.h"
|
||||
#include "../../../lib/events.h"
|
||||
#include "../unittests.h"
|
||||
#include "eventhelpers.h"
|
||||
#include "platform_helper.h"
|
||||
#include <vector>
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
namespace {
|
||||
|
||||
class MouseObserver : public IMouseObserver
|
||||
{
|
||||
public:
|
||||
void reset ()
|
||||
{
|
||||
enteredViews.clear ();
|
||||
exitedViews.clear ();
|
||||
}
|
||||
void onMouseEntered (CView* view, CFrame* frame) override { enteredViews.push_back (view); }
|
||||
void onMouseExited (CView* view, CFrame* frame) override { exitedViews.push_back (view); }
|
||||
void onMouseEvent (MouseEvent&, CFrame*) override {}
|
||||
|
||||
std::vector<CView*> enteredViews;
|
||||
std::vector<CView*> exitedViews;
|
||||
};
|
||||
|
||||
bool contains (const std::vector<CView*>& c, CView* view)
|
||||
{
|
||||
auto it = std::find (c.begin (), c.end (), view);
|
||||
return it != c.end ();
|
||||
}
|
||||
|
||||
class View : public CView
|
||||
{
|
||||
public:
|
||||
View () : CView (CRect (0, 0, 10, 10)) {}
|
||||
bool onMouseDownCalled {false};
|
||||
bool onKeyDownCalled {false};
|
||||
bool onKeyUpCalled {false};
|
||||
CMouseEventResult onMouseDown (CPoint& p, const CButtonState& buttons) override
|
||||
{
|
||||
onMouseDownCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
#if VSTGUI_ENABLE_DEPRECATED_METHODS
|
||||
int32_t onKeyDown (VstKeyCode& key) override
|
||||
{
|
||||
onKeyDownCalled = true;
|
||||
return 1;
|
||||
}
|
||||
int32_t onKeyUp (VstKeyCode& key) override
|
||||
{
|
||||
onKeyUpCalled = true;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
void onKeyboardEvent (KeyboardEvent& event) override
|
||||
{
|
||||
if (event.type == EventType::KeyDown)
|
||||
{
|
||||
onKeyDownCalled = true;
|
||||
event.consumed = true;
|
||||
}
|
||||
else if (event.type == EventType::KeyUp)
|
||||
{
|
||||
onKeyUpCalled = true;
|
||||
event.consumed = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
class ContainerTestingKeyboardEvents : public CViewContainer
|
||||
{
|
||||
public:
|
||||
bool onKeyDownCalled {false};
|
||||
bool onKeyUpCalled {false};
|
||||
|
||||
ContainerTestingKeyboardEvents () : CViewContainer (CRect (0, 0, 20, 20)) {}
|
||||
|
||||
#if VSTGUI_ENABLE_DEPRECATED_METHODS
|
||||
int32_t onKeyDown (VstKeyCode& key) override
|
||||
{
|
||||
if (onKeyDownCalled)
|
||||
return -1;
|
||||
onKeyDownCalled = true;
|
||||
return 1;
|
||||
}
|
||||
int32_t onKeyUp (VstKeyCode& key) override
|
||||
{
|
||||
if (onKeyUpCalled)
|
||||
return -1;
|
||||
onKeyUpCalled = true;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
void onKeyboardEvent (KeyboardEvent& event) override
|
||||
{
|
||||
if (event.type == EventType::KeyDown)
|
||||
{
|
||||
onKeyDownCalled = true;
|
||||
event.consumed = true;
|
||||
}
|
||||
else if (event.type == EventType::KeyUp)
|
||||
{
|
||||
onKeyUpCalled = true;
|
||||
event.consumed = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
class KeyboardHook : public IKeyboardHook
|
||||
{
|
||||
public:
|
||||
bool keyDownCalled {false};
|
||||
bool keyUpCalled {false};
|
||||
|
||||
void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) override
|
||||
{
|
||||
if (event.type == EventType::KeyDown)
|
||||
{
|
||||
keyDownCalled = true;
|
||||
}
|
||||
else if (event.type == EventType::KeyUp)
|
||||
{
|
||||
keyUpCalled = true;
|
||||
}
|
||||
event.consumed = true;
|
||||
}
|
||||
};
|
||||
|
||||
class CollectInvalidRectView : public CView
|
||||
{
|
||||
public:
|
||||
CRect redrawRect;
|
||||
uint32_t callCount {0};
|
||||
|
||||
CollectInvalidRectView () : CView (CRect (0, 0, 10, 10)) {}
|
||||
|
||||
CMouseEventResult onMouseDown (CPoint& p, const CButtonState& buttons) override
|
||||
{
|
||||
invalidRect (CRect (3, 3, 8, 8));
|
||||
invalidRect (CRect (0, 0, 8, 8));
|
||||
invalidRect (CRect (1, 1, 2, 2));
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
void drawRect (CDrawContext* c, const CRect& r) override
|
||||
{
|
||||
++callCount;
|
||||
redrawRect = r;
|
||||
CView::drawRect (c, r);
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymouse
|
||||
|
||||
TEST_CASE (CFrameTest, SetZoom)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
EXPECT (frame->setZoom (0.) == false);
|
||||
EXPECT (frame->setZoom (2.) == true);
|
||||
EXPECT (frame->getViewSize () == CRect (0, 0, 200, 200));
|
||||
EXPECT (frame->setZoom (0.5) == true);
|
||||
EXPECT (frame->getViewSize () == CRect (0, 0, 50, 50));
|
||||
EXPECT (frame->setZoom (1.0) == true);
|
||||
EXPECT (frame->getViewSize () == CRect (0, 0, 100, 100));
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, MouseEnterExit)
|
||||
{
|
||||
MouseObserver observer;
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
frame->registerMouseObserver (&observer);
|
||||
auto v1 = new View ();
|
||||
auto v2 = new View ();
|
||||
CRect r2 (10, 10, 20, 20);
|
||||
v2->setViewSize (r2);
|
||||
v2->setMouseableArea (r2);
|
||||
frame->addView (v1);
|
||||
frame->addView (v2);
|
||||
frame->attached (frame);
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {30., 30.});
|
||||
EXPECT (observer.enteredViews.size () == 0);
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {19., 19.});
|
||||
EXPECT (observer.enteredViews.size () == 1);
|
||||
EXPECT (contains (observer.enteredViews, v2));
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {9., 9.});
|
||||
EXPECT (observer.enteredViews.size () == 1);
|
||||
EXPECT (contains (observer.enteredViews, v1));
|
||||
EXPECT (observer.exitedViews.size () == 1);
|
||||
EXPECT (contains (observer.exitedViews, v2));
|
||||
frame->unregisterMouseObserver (&observer);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, MouseEnterExitInContainer)
|
||||
{
|
||||
MouseObserver observer;
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
frame->registerMouseObserver (&observer);
|
||||
auto v1 = new View ();
|
||||
auto v2 = new View ();
|
||||
CRect r2 (10, 10, 20, 20);
|
||||
v2->setViewSize (r2);
|
||||
v2->setMouseableArea (r2);
|
||||
auto container = new CViewContainer (CRect (0, 0, 80, 80));
|
||||
auto container2 = new CViewContainer (CRect (0, 0, 50, 50));
|
||||
frame->addView (container);
|
||||
container->addView (container2);
|
||||
container2->addView (v1);
|
||||
container2->addView (v2);
|
||||
frame->attached (frame);
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {90., 90.});
|
||||
EXPECT (observer.enteredViews.size () == 0);
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {79., 79.});
|
||||
EXPECT (observer.enteredViews.size () == 1);
|
||||
EXPECT (contains (observer.enteredViews, container));
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {49., 49.});
|
||||
EXPECT (observer.enteredViews.size () == 1);
|
||||
EXPECT (contains (observer.enteredViews, container2));
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {19., 19.});
|
||||
EXPECT (observer.enteredViews.size () == 1);
|
||||
EXPECT (contains (observer.enteredViews, v2));
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {18., 18.});
|
||||
EXPECT (observer.enteredViews.size () == 0);
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {9., 9.});
|
||||
EXPECT (observer.enteredViews.size () == 1);
|
||||
EXPECT (contains (observer.enteredViews, v1));
|
||||
EXPECT (observer.exitedViews.size () == 1);
|
||||
EXPECT (contains (observer.exitedViews, v2));
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {51., 51.});
|
||||
EXPECT (observer.enteredViews.size () == 0);
|
||||
EXPECT (observer.exitedViews.size () == 2);
|
||||
EXPECT (contains (observer.exitedViews, v1));
|
||||
EXPECT (contains (observer.exitedViews, container2));
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {81., 81.});
|
||||
EXPECT (observer.enteredViews.size () == 0);
|
||||
EXPECT (observer.exitedViews.size () == 1);
|
||||
EXPECT (contains (observer.exitedViews, container));
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {9., 9.});
|
||||
EXPECT (observer.enteredViews.size () == 3);
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
EXPECT (contains (observer.enteredViews, container));
|
||||
EXPECT (contains (observer.enteredViews, container2));
|
||||
EXPECT (contains (observer.enteredViews, v1));
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {81., 81.});
|
||||
EXPECT (observer.enteredViews.size () == 0);
|
||||
EXPECT (observer.exitedViews.size () == 3);
|
||||
EXPECT (contains (observer.exitedViews, container));
|
||||
EXPECT (contains (observer.exitedViews, container2));
|
||||
EXPECT (contains (observer.exitedViews, v1));
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {79., 79.});
|
||||
EXPECT (observer.enteredViews.size () == 1);
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
EXPECT (contains (observer.enteredViews, container));
|
||||
observer.reset ();
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {8., 8.});
|
||||
EXPECT (observer.enteredViews.size () == 2);
|
||||
EXPECT (observer.exitedViews.size () == 0);
|
||||
EXPECT (contains (observer.enteredViews, container2));
|
||||
EXPECT (contains (observer.enteredViews, v1));
|
||||
observer.reset ();
|
||||
|
||||
frame->unregisterMouseObserver (&observer);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, MouseMoveInContainer)
|
||||
{
|
||||
struct TestViewContainer : CViewContainer
|
||||
{
|
||||
using CViewContainer::CViewContainer;
|
||||
CPoint mouseMoveEventPos {};
|
||||
CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
mouseMoveEventPos = where;
|
||||
return CViewContainer::onMouseMoved (where, buttons);
|
||||
}
|
||||
};
|
||||
struct TestView : CView
|
||||
{
|
||||
using CView::CView;
|
||||
|
||||
CPoint mouseMoveEventPos {};
|
||||
CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
mouseMoveEventPos = where;
|
||||
return kMouseEventNotHandled;
|
||||
}
|
||||
};
|
||||
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto container = new TestViewContainer (CRect (10, 10, 80, 80));
|
||||
frame->addView (container);
|
||||
|
||||
auto testView = new TestView ({10, 10, 60, 60});
|
||||
container->addView (testView);
|
||||
|
||||
frame->attached (frame);
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (frame, {30., 30.}, MouseButton::None),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (container->mouseMoveEventPos, CPoint (30., 30.));
|
||||
EXPECT_EQ (testView->mouseMoveEventPos, CPoint (20., 20.));
|
||||
|
||||
container->mouseMoveEventPos = {};
|
||||
testView->mouseMoveEventPos = {};
|
||||
|
||||
CGraphicsTransform tm;
|
||||
tm.scale (2., 2.);
|
||||
container->setTransform (tm);
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (frame, {30., 30.}, MouseButton::None),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (container->mouseMoveEventPos, CPoint (30., 30.));
|
||||
EXPECT_EQ (testView->mouseMoveEventPos, CPoint (10., 10.));
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, RemoveViewWhileMouseInside)
|
||||
{
|
||||
MouseObserver observer;
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
frame->registerMouseObserver (&observer);
|
||||
auto v1 = new View ();
|
||||
frame->addView (v1);
|
||||
frame->attached (frame);
|
||||
dispatchMouseEvent<MouseMoveEvent> (frame, {5., 5.});
|
||||
EXPECT (contains (observer.enteredViews, v1));
|
||||
observer.reset ();
|
||||
frame->removeView (v1);
|
||||
EXPECT (contains (observer.exitedViews, v1));
|
||||
frame->unregisterMouseObserver (&observer);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, FocusSettings)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
EXPECT (frame->getFocusColor () == kRedCColor);
|
||||
EXPECT (frame->getFocusWidth () == 2.);
|
||||
EXPECT (frame->focusDrawingEnabled () == false);
|
||||
frame->setFocusColor (kWhiteCColor);
|
||||
EXPECT (frame->getFocusColor () == kWhiteCColor);
|
||||
frame->setFocusColor (kGreenCColor);
|
||||
EXPECT (frame->getFocusColor () == kGreenCColor);
|
||||
frame->setFocusWidth (5.);
|
||||
EXPECT (frame->getFocusWidth () == 5.);
|
||||
frame->setFocusWidth (8.);
|
||||
EXPECT (frame->getFocusWidth () == 8.);
|
||||
frame->setFocusDrawingEnabled (true);
|
||||
EXPECT (frame->focusDrawingEnabled () == true);
|
||||
frame->setFocusDrawingEnabled (false);
|
||||
EXPECT (frame->focusDrawingEnabled () == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, SetModalView)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto view = shared (new View ());
|
||||
EXPECT (frame->getModalView () == nullptr);
|
||||
auto session = frame->beginModalViewSession (view);
|
||||
EXPECT (session);
|
||||
EXPECT (frame->getModalView () == view);
|
||||
auto container = shared (new CViewContainer (CRect (0, 0, 0, 0)));
|
||||
auto session2 = frame->beginModalViewSession (container);
|
||||
EXPECT (session2)
|
||||
EXPECT (frame->getModalView () == container);
|
||||
EXPECT (frame->endModalViewSession (*session) == false);
|
||||
EXPECT (frame->endModalViewSession (*session2) == true);
|
||||
EXPECT (frame->getModalView () == view);
|
||||
EXPECT (frame->endModalViewSession (*session) == true);
|
||||
EXPECT (frame->getModalView () == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, KeyDownEvent)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto view = new View ();
|
||||
frame->addView (view);
|
||||
frame->attached (frame);
|
||||
frame->onActivate (true);
|
||||
KeyboardEvent event;
|
||||
event.type = EventType::KeyDown;
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
frame->setFocusView (view);
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
event.consumed = false;
|
||||
EXPECT (view->onKeyDownCalled);
|
||||
frame->removeAll ();
|
||||
auto container = new ContainerTestingKeyboardEvents ();
|
||||
auto view2 = new CView (CRect (0, 0, 10, 10));
|
||||
container->addView (view2);
|
||||
frame->addView (container);
|
||||
frame->setFocusView (view2);
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
event.consumed = false;
|
||||
EXPECT (container->onKeyDownCalled);
|
||||
frame->setFocusView (nullptr);
|
||||
view2->setWantsFocus (true);
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
event.virt = VirtualKey::Tab;
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
event.consumed = false;
|
||||
EXPECT (frame->getFocusView () == view2);
|
||||
auto view3 = shared (new View ());
|
||||
auto modalSession = frame->beginModalViewSession (view3);
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (view3->onKeyDownCalled);
|
||||
frame->endModalViewSession (*modalSession);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, KeyUpEvent)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto view = new View ();
|
||||
frame->addView (view);
|
||||
frame->attached (frame);
|
||||
frame->onActivate (true);
|
||||
KeyboardEvent event;
|
||||
event.type = EventType::KeyUp;
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
frame->setFocusView (view);
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
event.consumed = false;
|
||||
EXPECT (view->onKeyUpCalled);
|
||||
frame->removeAll ();
|
||||
auto container = new ContainerTestingKeyboardEvents ();
|
||||
auto view2 = new CView (CRect (0, 0, 10, 10));
|
||||
container->addView (view2);
|
||||
frame->addView (container);
|
||||
frame->setFocusView (view2);
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
event.consumed = false;
|
||||
EXPECT (container->onKeyUpCalled);
|
||||
auto view3 = shared (new View ());
|
||||
auto modalSession = frame->beginModalViewSession (view3);
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (view3->onKeyUpCalled);
|
||||
frame->endModalViewSession (*modalSession);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, AdvanceNextFocusView)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto view = new View ();
|
||||
frame->attached (frame);
|
||||
frame->addView (view);
|
||||
frame->onActivate (true);
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
view->setWantsFocus (true);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view);
|
||||
frame->removeAll ();
|
||||
|
||||
auto container = new CViewContainer ({0., 0., 20., 20.});
|
||||
auto view2 = new View ();
|
||||
container->addView (view2);
|
||||
frame->addView (container);
|
||||
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
view2->setWantsFocus (true);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view2);
|
||||
auto container2 = new CViewContainer ({0., 0., 20., 20.});
|
||||
auto view3 = new View ();
|
||||
container2->addView (view3);
|
||||
container->addView (container2);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
view3->setWantsFocus (true);
|
||||
frame->setFocusView (view2);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view3);
|
||||
auto view4 = new View ();
|
||||
view4->setWantsFocus (true);
|
||||
container2->addView (view4);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view4);
|
||||
auto container3 = new CViewContainer ({0., 0., 20., 20.});
|
||||
auto view5 = new View ();
|
||||
view5->setWantsFocus (true);
|
||||
container3->addView (view5);
|
||||
container->addView (container3);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view5);
|
||||
auto view6 = new View ();
|
||||
view6->setWantsFocus (true);
|
||||
frame->addView (view6);
|
||||
frame->advanceNextFocusView (nullptr);
|
||||
EXPECT (frame->getFocusView () == view6);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, AdvanceNextFocusViewInModalView)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto view = shared (new View ());
|
||||
frame->attached (frame);
|
||||
auto modalSession = frame->beginModalViewSession (view);
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
frame->onActivate (true);
|
||||
view->setWantsFocus (true);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view);
|
||||
frame->endModalViewSession (*modalSession);
|
||||
auto container = shared (new CViewContainer ({0., 0., 20., 20.}));
|
||||
auto view2 = new View ();
|
||||
container->addView (view2);
|
||||
modalSession = frame->beginModalViewSession (container);
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
view2->setWantsFocus (true);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view2);
|
||||
auto container2 = new CViewContainer ({0., 0., 20., 20.});
|
||||
auto view3 = new View ();
|
||||
container2->addView (view3);
|
||||
container->addView (container2);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view2);
|
||||
view3->setWantsFocus (true);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view3);
|
||||
auto view4 = new View ();
|
||||
view4->setWantsFocus (true);
|
||||
container2->addView (view4);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view4);
|
||||
auto container3 = new CViewContainer ({0., 0., 20., 20.});
|
||||
auto view5 = new View ();
|
||||
view5->setWantsFocus (true);
|
||||
container3->addView (view5);
|
||||
container->addView (container3);
|
||||
frame->advanceNextFocusView (frame->getFocusView ());
|
||||
EXPECT (frame->getFocusView () == view5);
|
||||
|
||||
frame->endModalViewSession (*modalSession);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, GetViewAtModalView)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto container = new CViewContainer ({0., 0., 20., 20.});
|
||||
auto view = new View ();
|
||||
container->addView (view);
|
||||
frame->attached (frame);
|
||||
auto modalSession = frame->beginModalViewSession (container);
|
||||
EXPECT (frame->getViewAt (CPoint (1, 1)) == container);
|
||||
EXPECT (frame->getViewAt (CPoint (1, 1), GetViewOptions (GetViewOptions::kDeep)) == view);
|
||||
EXPECT (frame->getViewAt (CPoint (90, 90)) == nullptr);
|
||||
frame->endModalViewSession (*modalSession);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, GetContainerAtModalView)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto container = new CViewContainer ({0., 0., 20., 20.});
|
||||
CRect r (0, 0, 50, 50);
|
||||
container->setViewSize (r);
|
||||
container->setMouseableArea (r);
|
||||
auto container2 = new CViewContainer ({0., 0., 20., 20.});
|
||||
container->addView (container2);
|
||||
frame->attached (frame);
|
||||
EXPECT (frame->getContainerAt (CPoint (1, 1)) == frame);
|
||||
auto modalSession = frame->beginModalViewSession (container);
|
||||
EXPECT (frame->getContainerAt (CPoint (1, 1), GetViewOptions (GetViewOptions::kNone)) ==
|
||||
container);
|
||||
EXPECT (frame->getContainerAt (CPoint (1, 1), GetViewOptions (GetViewOptions::kDeep)) ==
|
||||
container2);
|
||||
EXPECT (frame->getContainerAt (CPoint (80, 80), GetViewOptions (GetViewOptions::kDeep)) ==
|
||||
nullptr);
|
||||
|
||||
frame->endModalViewSession (*modalSession);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, MouseDownModalView)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto container = new CViewContainer ({0., 0., 20., 20.});
|
||||
auto view1 = new View ();
|
||||
container->addView (view1);
|
||||
frame->attached (frame);
|
||||
auto modalSession = frame->beginModalViewSession (container);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (frame, {80., 80.}, MouseButton::Left),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_FALSE (view1->onMouseDownCalled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (frame, {1., 1.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (view1->onMouseDownCalled);
|
||||
|
||||
frame->endModalViewSession (*modalSession);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, Activate)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto view = new View ();
|
||||
view->setWantsFocus (true);
|
||||
auto view2 = new View ();
|
||||
view2->setWantsFocus (true);
|
||||
frame->addView (view);
|
||||
frame->addView (view2);
|
||||
frame->attached (frame);
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
frame->onActivate (false);
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
frame->onActivate (true);
|
||||
EXPECT (frame->getFocusView () == view);
|
||||
frame->setFocusView (view2);
|
||||
frame->onActivate (false);
|
||||
EXPECT (frame->getFocusView () == nullptr);
|
||||
frame->onActivate (true);
|
||||
EXPECT (frame->getFocusView () == view2);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, KeyboardHook)
|
||||
{
|
||||
KeyboardHook hook;
|
||||
EXPECT (hook.keyDownCalled == false);
|
||||
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
frame->attached (frame);
|
||||
frame->registerKeyboardHook (&hook);
|
||||
KeyboardEvent event;
|
||||
event.type = EventType::KeyDown;
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (hook.keyDownCalled);
|
||||
EXPECT (hook.keyUpCalled == false);
|
||||
event.type = EventType::KeyUp;
|
||||
frame->dispatchEvent (event);
|
||||
EXPECT (hook.keyUpCalled);
|
||||
|
||||
frame->unregisterKeyboardHook (&hook);
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, Open)
|
||||
{
|
||||
auto platformHandle = UnitTest::PlatformParentHandle::create ();
|
||||
EXPECT (platformHandle);
|
||||
auto frame = new CFrame (CRect (0, 0, 100, 100), nullptr);
|
||||
EXPECT (frame->open (nullptr) == false);
|
||||
EXPECT (frame->open (platformHandle->getHandle (), platformHandle->getType ()));
|
||||
frame->close ();
|
||||
}
|
||||
|
||||
TEST_CASE (CFrameTest, SetPosition)
|
||||
{
|
||||
auto platformHandle = UnitTest::PlatformParentHandle::create ();
|
||||
EXPECT (platformHandle);
|
||||
auto frame = new CFrame (CRect (0, 0, 100, 100), nullptr);
|
||||
frame->open (platformHandle->getHandle (), platformHandle->getType ());
|
||||
EXPECT (frame->setPosition (10, 10));
|
||||
CRect r;
|
||||
frame->getSize (r);
|
||||
EXPECT (r == CRect (10, 10, 110, 110));
|
||||
frame->close ();
|
||||
}
|
||||
|
||||
#if 0
|
||||
TEST_CASE (CFrameTest, CollectInvalidRectsOnMouseDown)
|
||||
{
|
||||
// It is expected that this test failes on Mac OS X 10.11 because of OS changes
|
||||
auto platformHandle = UnitTest::PlatformParentHandle::create ();
|
||||
auto frame = new CFrame (CRect (0, 0, 100, 100), nullptr);
|
||||
auto view = new CollectInvalidRectView ();
|
||||
frame->addView (view);
|
||||
frame->open (platformHandle->getHandle (), platformHandle->getType ());
|
||||
platformHandle->forceRedraw ();
|
||||
EXPECT (view->callCount == 1);
|
||||
EXPECT (view->redrawRect == view->getViewSize ());
|
||||
|
||||
auto platformFrameCallback = dynamic_cast<IPlatformFrameCallback*> (frame);
|
||||
MouseDownEvent downEvent (CPoint (), MouseButton::Left);
|
||||
platformFrameCallback->platformOnEvent (downEvent);
|
||||
platformHandle->forceRedraw ();
|
||||
EXPECT (view->redrawRect == CRect (0, 0, 8, 8));
|
||||
EXPECT (view->callCount == 2);
|
||||
frame->close ();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if VSTGUI_ENABLE_DEPRECATED_METHODS
|
||||
#include "../../../lib/private/disabledeprecatedmessage.h"
|
||||
|
||||
TEST_CASE (CFameLegacyTest, SetModalView)
|
||||
{
|
||||
auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr));
|
||||
auto view = owned (new View ());
|
||||
EXPECT (frame->getModalView () == nullptr);
|
||||
EXPECT (frame->setModalView (view));
|
||||
EXPECT (frame->getModalView () == view);
|
||||
auto container = owned (new CViewContainer (CRect (0, 0, 0, 0)));
|
||||
EXPECT (frame->setModalView (container) == false);
|
||||
EXPECT (frame->setModalView (nullptr));
|
||||
EXPECT (frame->setModalView (container));
|
||||
EXPECT (frame->getModalView () == container);
|
||||
EXPECT (frame->setModalView (nullptr));
|
||||
EXPECT (frame->getModalView () == nullptr);
|
||||
}
|
||||
|
||||
#include "../../../lib/private/enabledeprecatedmessage.h"
|
||||
#endif
|
||||
|
||||
} // VSTGUI
|
||||
+50
@@ -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/cinvalidrectlist.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CInvalidRectListTest, RectEqual)
|
||||
{
|
||||
CInvalidRectList list;
|
||||
EXPECT_TRUE (list.add ({0, 0, 100, 100}));
|
||||
EXPECT_FALSE (list.add ({0, 0, 100, 100}));
|
||||
EXPECT_EQ (list.data ().size (), 1u);
|
||||
}
|
||||
|
||||
TEST_CASE (CInvalidRectListTest, AddBiggerOne)
|
||||
{
|
||||
CInvalidRectList list;
|
||||
EXPECT_TRUE (list.add ({0, 0, 100, 100}));
|
||||
EXPECT_TRUE (list.add ({0, 0, 200, 200}));
|
||||
EXPECT_EQ (list.data ().size (), 1u);
|
||||
}
|
||||
|
||||
TEST_CASE (CInvalidRectListTest, AddSmallerOne)
|
||||
{
|
||||
CInvalidRectList list;
|
||||
EXPECT_TRUE (list.add ({0, 0, 100, 100}));
|
||||
EXPECT_FALSE (list.add ({10, 10, 20, 20}));
|
||||
EXPECT_EQ (list.data ().size (), 1u);
|
||||
}
|
||||
|
||||
TEST_CASE (CInvalidRectListTest, AddOverlappingOne)
|
||||
{
|
||||
CInvalidRectList list;
|
||||
EXPECT_TRUE (list.add ({0, 0, 100, 100}));
|
||||
EXPECT_TRUE (list.add ({90, 0, 120, 100}));
|
||||
EXPECT_EQ (list.data ().size (), 1u);
|
||||
}
|
||||
|
||||
TEST_CASE (CInvalidRectListTest, AddMulti)
|
||||
{
|
||||
CInvalidRectList list;
|
||||
EXPECT_TRUE (list.add ({0, 0, 10, 10}));
|
||||
EXPECT_TRUE (list.add ({20, 20, 30, 30}));
|
||||
EXPECT_EQ (list.data ().size (), 2u);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,113 @@
|
||||
// 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/clinestyle.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CLineStyleTest, DefaultConstructor)
|
||||
{
|
||||
CLineStyle style;
|
||||
EXPECT (style.getLineCap () == CLineStyle::kLineCapButt);
|
||||
EXPECT (style.getLineJoin () == CLineStyle::kLineJoinMiter);
|
||||
EXPECT (style.getDashPhase () == 0.);
|
||||
EXPECT (style.getDashCount () == 0);
|
||||
EXPECT (style.getDashLengths ().size () == 0);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, SolidLine)
|
||||
{
|
||||
CLineStyle style;
|
||||
EXPECT (style == kLineSolid);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, OnOffDashLine)
|
||||
{
|
||||
CLineStyle style (CLineStyle::kLineCapButt, CLineStyle::kLineJoinMiter, 0., {1., 1.});
|
||||
EXPECT (kLineOnOffDash == style);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, DashLengths)
|
||||
{
|
||||
CLineStyle style (CLineStyle::kLineCapButt, CLineStyle::kLineJoinMiter, 0., {1., 3., 2.});
|
||||
EXPECT (style.getDashCount () == 3);
|
||||
const auto& dashLengths = style.getDashLengths ();
|
||||
EXPECT (dashLengths[0] == 1.);
|
||||
EXPECT (dashLengths[1] == 3.);
|
||||
EXPECT (dashLengths[2] == 2.);
|
||||
style.getDashLengths ().push_back (6.);
|
||||
EXPECT (style.getDashCount () == 4);
|
||||
EXPECT (style.getDashLengths ()[3] == 6.);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, LineCap)
|
||||
{
|
||||
CLineStyle style;
|
||||
style.setLineCap (CLineStyle::kLineCapButt);
|
||||
EXPECT (style.getLineCap () == CLineStyle::kLineCapButt);
|
||||
style.setLineCap (CLineStyle::kLineCapRound);
|
||||
EXPECT (style.getLineCap () == CLineStyle::kLineCapRound);
|
||||
style.setLineCap (CLineStyle::kLineCapSquare);
|
||||
EXPECT (style.getLineCap () == CLineStyle::kLineCapSquare);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, LineJoin)
|
||||
{
|
||||
CLineStyle style;
|
||||
style.setLineJoin (CLineStyle::kLineJoinMiter);
|
||||
EXPECT (style.getLineJoin () == CLineStyle::kLineJoinMiter);
|
||||
style.setLineJoin (CLineStyle::kLineJoinRound);
|
||||
EXPECT (style.getLineJoin () == CLineStyle::kLineJoinRound);
|
||||
style.setLineJoin (CLineStyle::kLineJoinBevel);
|
||||
EXPECT (style.getLineJoin () == CLineStyle::kLineJoinBevel);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, DashPhase)
|
||||
{
|
||||
CLineStyle style;
|
||||
style.setDashPhase (1.5);
|
||||
EXPECT (style.getDashPhase () == 1.5);
|
||||
style.setDashPhase (2.5);
|
||||
EXPECT (style.getDashPhase () == 2.5);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, CopyConstructor)
|
||||
{
|
||||
CLineStyle style;
|
||||
style.setDashPhase (2.);
|
||||
style.getDashLengths ().push_back (1.);
|
||||
style.getDashLengths ().push_back (2.);
|
||||
CLineStyle s2 (style);
|
||||
EXPECT (style.getLineCap () == CLineStyle::kLineCapButt);
|
||||
EXPECT (style.getLineJoin () == CLineStyle::kLineJoinMiter);
|
||||
EXPECT (style.getDashPhase () == 2.);
|
||||
EXPECT (style.getDashCount () == 2);
|
||||
EXPECT (style.getDashLengths ()[0] == 1.);
|
||||
EXPECT (style.getDashLengths ()[1] == 2.);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, MoveConstructor)
|
||||
{
|
||||
CLineStyle style;
|
||||
style.getDashLengths ().push_back (1.);
|
||||
style.getDashLengths ().push_back (2.);
|
||||
CLineStyle s2 (std::move (style));
|
||||
EXPECT (style.getDashCount () == 0);
|
||||
EXPECT (s2.getDashCount () == 2);
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, VectorConstructor)
|
||||
{
|
||||
CLineStyle::CoordVector dashLengths ({2., 4.});
|
||||
CLineStyle style (CLineStyle::kLineCapButt, CLineStyle::kLineJoinMiter, 0., dashLengths);
|
||||
EXPECT (dashLengths == style.getDashLengths ());
|
||||
}
|
||||
|
||||
TEST_CASE (CLineStyleTest, UnequalOperator)
|
||||
{
|
||||
EXPECT (kLineSolid != kLineOnOffDash);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
// 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 "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CCheckboxTest, MouseEvents)
|
||||
{
|
||||
auto b = owned (new CCheckBox (CRect (10, 10, 50, 20)));
|
||||
b->setValue (b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Right),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {0., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
MouseCancelEvent cancelEvent;
|
||||
b->dispatchEvent (cancelEvent);
|
||||
EXPECT_TRUE (cancelEvent.consumed);
|
||||
EXPECT (b->isEditing () == false);
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
}
|
||||
|
||||
TEST_CASE (CCheckboxTest, KeyEvents)
|
||||
{
|
||||
auto b = owned (new CCheckBox (CRect (10, 10, 50, 20)));
|
||||
b->setValue (b->getMin ());
|
||||
KeyboardEvent event;
|
||||
event.virt = VirtualKey::Return;
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b->getValue () == b->getMax ());
|
||||
event.consumed.reset ();
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b->getValue () == b->getMin ());
|
||||
|
||||
event.virt = VirtualKey::None;
|
||||
event.character = 't';
|
||||
event.consumed.reset ();
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_FALSE (event.consumed);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
// 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 "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
namespace {
|
||||
|
||||
class Control : public CControl
|
||||
{
|
||||
public:
|
||||
Control () : CControl (CRect (0, 0, 10, 10)) {}
|
||||
void draw (CDrawContext* pContext) override {}
|
||||
|
||||
#if VSTGUI_ENABLE_DEPRECATED_METHODS
|
||||
static int32_t mapVstKeyModifier (int32_t vstModifier)
|
||||
{
|
||||
#include "../../../../lib/private/disabledeprecatedmessage.h"
|
||||
return CControl::mapVstKeyModifier (vstModifier);
|
||||
#include "../../../../lib/private/enabledeprecatedmessage.h"
|
||||
}
|
||||
#endif
|
||||
|
||||
CLASS_METHODS (Control, CControl)
|
||||
};
|
||||
|
||||
struct Listener : IControlListener
|
||||
{
|
||||
bool valueChangedCalled {false};
|
||||
bool beginEditCalled {false};
|
||||
bool endEditCalled {false};
|
||||
|
||||
void valueChanged (CControl* pControl) override { valueChangedCalled = true; }
|
||||
void controlBeginEdit (CControl* pControl) override { beginEditCalled = true; }
|
||||
void controlEndEdit (CControl* pControl) override { endEditCalled = true; }
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE (CControlTest, Editing)
|
||||
{
|
||||
Control c;
|
||||
c.beginEdit ();
|
||||
EXPECT (c.isEditing ());
|
||||
c.setValue (0.5f);
|
||||
c.endEdit ();
|
||||
EXPECT (c.isEditing () == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CControlTest, Listener)
|
||||
{
|
||||
Control c;
|
||||
Listener l;
|
||||
c.setListener (&l);
|
||||
c.beginEdit ();
|
||||
EXPECT (l.beginEditCalled);
|
||||
c.setValue (0.5f);
|
||||
c.valueChanged ();
|
||||
EXPECT (l.valueChangedCalled);
|
||||
c.endEdit ();
|
||||
EXPECT (l.endEditCalled);
|
||||
}
|
||||
|
||||
TEST_CASE (CControlTest, SubListener)
|
||||
{
|
||||
Control c;
|
||||
Listener l;
|
||||
c.registerControlListener (&l);
|
||||
c.beginEdit ();
|
||||
EXPECT (l.beginEditCalled);
|
||||
c.setValue (0.5f);
|
||||
c.valueChanged ();
|
||||
EXPECT (l.valueChangedCalled);
|
||||
c.endEdit ();
|
||||
EXPECT (l.endEditCalled);
|
||||
c.unregisterControlListener (&l);
|
||||
}
|
||||
|
||||
TEST_CASE (CControlTest, SetValueOutOfRange)
|
||||
{
|
||||
Control c;
|
||||
EXPECT (c.getMin () == 0.f);
|
||||
EXPECT (c.getMax () == 1.f);
|
||||
c.setValue (0.5f);
|
||||
EXPECT (c.getValue () == 0.5f);
|
||||
c.setValue (-0.5f);
|
||||
EXPECT (c.getValue () == 0.f);
|
||||
c.setValue (1.5f);
|
||||
EXPECT (c.getValue () == 1.f);
|
||||
}
|
||||
|
||||
TEST_CASE (CControlTest, SetValueNormalized)
|
||||
{
|
||||
Control c;
|
||||
c.setMin (1.f);
|
||||
c.setMax (2.f);
|
||||
c.setValueNormalized (0.f);
|
||||
EXPECT (c.getValue () == 1.f);
|
||||
c.setValueNormalized (1.f);
|
||||
EXPECT (c.getValue () == 2.f);
|
||||
c.setValueNormalized (0.5f);
|
||||
EXPECT (c.getValue () == 1.5f);
|
||||
|
||||
c.setValueNormalized (-1.f);
|
||||
EXPECT (c.getValue () == 1.f);
|
||||
c.setValueNormalized (2.f);
|
||||
EXPECT (c.getValue () == 2.f);
|
||||
}
|
||||
|
||||
TEST_CASE (CControlTest, CheckDefaultValue)
|
||||
{
|
||||
Control c;
|
||||
c.setValue (c.getDefaultValue () + 0.1f);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (&c, {0., 0.}, MouseButton::Left,
|
||||
Modifiers (ModifierKey::Control)),
|
||||
EventConsumeState::Handled + MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT (c.getValue () == c.getDefaultValue ());
|
||||
c.setValue (c.getDefaultValue () + 0.1f);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (&c, {0., 0.}, MouseButton::Right,
|
||||
Modifiers (ModifierKey::Control)),
|
||||
0);
|
||||
EXPECT (c.getValue () == c.getDefaultValue () + 0.1f);
|
||||
|
||||
auto oldCheckDefaultValueFunc = CControl::CheckDefaultValueEventFunc;
|
||||
CControl::CheckDefaultValueEventFunc = [] (CControl*, MouseDownEvent& event) {
|
||||
return (event.buttonState.isMiddle () && event.modifiers.is (ModifierKey::Shift));
|
||||
};
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (&c, {0., 0.}, MouseButton::Left,
|
||||
Modifiers (ModifierKey::Control)),
|
||||
0);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (&c, {0., 0.}, MouseButton::Middle,
|
||||
Modifiers (ModifierKey::Shift)),
|
||||
EventConsumeState::Handled + MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
|
||||
CControl::CheckDefaultValueEventFunc = oldCheckDefaultValueFunc;
|
||||
}
|
||||
|
||||
#if VSTGUI_ENABLE_DEPRECATED_METHODS
|
||||
TEST_CASE (CControlTest, mapVstKeyModifier)
|
||||
{
|
||||
EXPECT (Control::mapVstKeyModifier (MODIFIER_SHIFT) == kShift);
|
||||
EXPECT (Control::mapVstKeyModifier (MODIFIER_ALTERNATE) == kAlt);
|
||||
EXPECT (Control::mapVstKeyModifier (MODIFIER_COMMAND) == kApple);
|
||||
EXPECT (Control::mapVstKeyModifier (MODIFIER_CONTROL) == kControl);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // VSTGUI
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
// 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 "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CKickButtonTest, MouseEvents)
|
||||
{
|
||||
auto b = owned (new CKickButton (CRect (10, 10, 50, 20), nullptr, 0, nullptr));
|
||||
b->setValue (b->getMin ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Right),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {0., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseCancelEvent (b), EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
}
|
||||
|
||||
TEST_CASE (CKickButtonTest, KeyEvents)
|
||||
{
|
||||
auto b = owned (new CKickButton (CRect (10, 10, 50, 20), nullptr, 0, nullptr));
|
||||
b->setValue (b->getMin ());
|
||||
KeyboardEvent event;
|
||||
event.virt = VirtualKey::Return;
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
event.consumed.reset ();
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
event.consumed.reset ();
|
||||
event.type = EventType::KeyUp;
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
KeyboardEvent event2;
|
||||
event2.character = 't';
|
||||
b->onKeyboardEvent (event2);
|
||||
EXPECT_FALSE (event2.consumed);
|
||||
event2.type = EventType::KeyUp;
|
||||
b->onKeyboardEvent (event2);
|
||||
EXPECT_FALSE (event2.consumed);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+304
@@ -0,0 +1,304 @@
|
||||
// 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/clistcontrol.h"
|
||||
#include "../../../../lib/cscrollview.h"
|
||||
#include "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
static SharedPointer<CListControl>
|
||||
createTestListControl (CCoord rowHeight, int32_t numRows = 10,
|
||||
CListControlRowDesc::Flags rowFlags = CListControlRowDesc::Flags {
|
||||
CListControlRowDesc::Selectable | CListControlRowDesc::Hoverable})
|
||||
{
|
||||
auto listControl = makeOwned<CListControl> (CRect (0, 0, 100, 100));
|
||||
auto config = makeOwned<StaticListControlConfigurator> (rowHeight, rowFlags);
|
||||
listControl->setMin (0.f);
|
||||
listControl->setMax (static_cast<float> (numRows));
|
||||
listControl->setConfigurator (config);
|
||||
listControl->recalculateLayout ();
|
||||
listControl->setValue (0.f);
|
||||
return listControl;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
static SharedPointer<CScrollView> createScrollViewAndEmbedListControl (CViewContainer* parent,
|
||||
CListControl* listControl)
|
||||
{
|
||||
auto scrollView =
|
||||
makeOwned<CScrollView> (CRect (0, 0, 100, listControl->getHeight () / 2),
|
||||
listControl->getViewSize (), CScrollView::kVerticalScrollbar);
|
||||
scrollView->addView (listControl);
|
||||
listControl->remember ();
|
||||
parent->addView (scrollView);
|
||||
scrollView->attached (parent);
|
||||
return scrollView;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
static KeyboardEvent makeKeyboardEvent (int32_t c, VirtualKey virt,
|
||||
ModifierKey modifier = ModifierKey::None)
|
||||
{
|
||||
KeyboardEvent event;
|
||||
event.type = EventType::KeyDown;
|
||||
event.character = c;
|
||||
event.virt = virt;
|
||||
event.modifiers.add (modifier);
|
||||
return event;
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, minMax)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
auto listControl = createTestListControl (rowHeight);
|
||||
listControl->setMin (-5.f);
|
||||
listControl->setMax (5.f);
|
||||
|
||||
auto row = listControl->getRowAtPoint (CPoint (0, 0));
|
||||
EXPECT (row);
|
||||
if (row)
|
||||
{
|
||||
EXPECT (*row == -5);
|
||||
}
|
||||
row = listControl->getRowAtPoint (CPoint (0, listControl->getHeight () - 1));
|
||||
EXPECT (row);
|
||||
if (row)
|
||||
{
|
||||
EXPECT (*row == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, MouseRowSelection)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
auto listControl = createTestListControl (rowHeight);
|
||||
|
||||
dispatchMouseEvent<MouseDownEvent> (listControl, {0., rowHeight}, MouseButton::Left);
|
||||
dispatchMouseEvent<MouseUpEvent> (listControl, {0., rowHeight}, MouseButton::Left);
|
||||
EXPECT_EQ (listControl->getValue (), 1.f);
|
||||
dispatchMouseEvent<MouseDownEvent> (listControl, {0., rowHeight * 3.}, MouseButton::Left);
|
||||
dispatchMouseEvent<MouseUpEvent> (listControl, {0., rowHeight * 3.}, MouseButton::Left);
|
||||
EXPECT_EQ (listControl->getValue (), 3.f);
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, Hovering)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
constexpr auto numRows = 5;
|
||||
auto listControl = createTestListControl (rowHeight, numRows);
|
||||
|
||||
EXPECT_FALSE (listControl->getHoveredRow ());
|
||||
dispatchMouseEvent<MouseMoveEvent>(listControl, {10., 5.});
|
||||
EXPECT_TRUE (listControl->getHoveredRow ());
|
||||
EXPECT_EQ (*listControl->getHoveredRow (), 0);
|
||||
|
||||
dispatchMouseEvent<MouseMoveEvent>(listControl, {10., 5. + rowHeight});
|
||||
EXPECT_TRUE (listControl->getHoveredRow ());
|
||||
EXPECT_EQ (*listControl->getHoveredRow (), 1);
|
||||
|
||||
dispatchMouseEvent<MouseExitEvent>(listControl, {10., 5. + rowHeight});
|
||||
EXPECT_FALSE (listControl->getHoveredRow ());
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, RowRect)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
auto listControl = createTestListControl (rowHeight);
|
||||
|
||||
auto rr = listControl->getRowRect (1);
|
||||
EXPECT (rr);
|
||||
if (rr)
|
||||
{
|
||||
EXPECT (*rr == CRect (0, rowHeight, 100, rowHeight * 2.));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, KeyDownOnUnselectableRows)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
constexpr auto numRows = 20;
|
||||
auto listControl = createTestListControl (rowHeight, numRows, {});
|
||||
listControl->setValue (2.f);
|
||||
EXPECT (listControl->getValue () == 2.f);
|
||||
|
||||
auto event = makeKeyboardEvent (0, VirtualKey::Down);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
EXPECT (listControl->getValue () == 2.f);
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, KeyWithModifier)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
constexpr auto numRows = 20;
|
||||
auto listControl = createTestListControl (rowHeight, numRows, {});
|
||||
|
||||
listControl->setValue (1.f);
|
||||
|
||||
auto event = makeKeyboardEvent (0, VirtualKey::Down, ModifierKey::Shift);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
EXPECT (listControl->getValue () == 1.f);
|
||||
|
||||
event = makeKeyboardEvent (0, VirtualKey::Up, ModifierKey::Shift);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
EXPECT (listControl->getValue () == 1.f);
|
||||
|
||||
event = makeKeyboardEvent (0, VirtualKey::Home, ModifierKey::Shift);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
EXPECT (listControl->getValue () == 1.f);
|
||||
|
||||
event = makeKeyboardEvent (0, VirtualKey::End, ModifierKey::Shift);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
EXPECT (listControl->getValue () == 1.f);
|
||||
|
||||
event = makeKeyboardEvent (0, VirtualKey::PageUp, ModifierKey::Shift);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
EXPECT (listControl->getValue () == 1.f);
|
||||
|
||||
event = makeKeyboardEvent (0, VirtualKey::PageDown, ModifierKey::Shift);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
EXPECT (listControl->getValue () == 1.f);
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, KeyHome)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
auto listControl = createTestListControl (rowHeight);
|
||||
listControl->setValue (5.f);
|
||||
EXPECT (listControl->getValue () == 5.f);
|
||||
|
||||
auto event = makeKeyboardEvent (0, VirtualKey::Home);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 0.f);
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, KeyEnd)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
constexpr auto numRows = 20;
|
||||
auto listControl = createTestListControl (rowHeight, numRows);
|
||||
listControl->setValue (0.f);
|
||||
EXPECT (listControl->getValue () == 0.f);
|
||||
|
||||
auto event = makeKeyboardEvent (0, VirtualKey::End);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == numRows);
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, KeyUp)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
constexpr auto numRows = 20;
|
||||
auto listControl = createTestListControl (rowHeight, numRows);
|
||||
listControl->setValue (2.f);
|
||||
EXPECT (listControl->getValue () == 2.f);
|
||||
|
||||
auto event = makeKeyboardEvent (0, VirtualKey::Up);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 1.f);
|
||||
event.consumed.reset ();
|
||||
|
||||
listControl->setValue (0.f);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == numRows);
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, KeyDown)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
constexpr auto numRows = 20;
|
||||
auto listControl = createTestListControl (rowHeight, numRows);
|
||||
listControl->setValue (2.f);
|
||||
EXPECT (listControl->getValue () == 2.f);
|
||||
|
||||
auto event = makeKeyboardEvent (0, VirtualKey::Down);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 3.f);
|
||||
event.consumed.reset ();
|
||||
|
||||
listControl->setValue (numRows);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 0.f);
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, PageUp)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
constexpr auto numRows = 30;
|
||||
auto parent = makeOwned<CViewContainer> (CRect (0, 0, 1000, 1000));
|
||||
auto listControl = createTestListControl (rowHeight, numRows);
|
||||
auto scrollView = createScrollViewAndEmbedListControl (parent, listControl);
|
||||
listControl->setValue (numRows);
|
||||
auto rect = listControl->getRowRect (0);
|
||||
scrollView->makeRectVisible (*rect);
|
||||
|
||||
auto event = makeKeyboardEvent (0, VirtualKey::PageUp);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 15.f);
|
||||
event.consumed.reset ();
|
||||
|
||||
listControl->setValue (16);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 15.f);
|
||||
event.consumed.reset ();
|
||||
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 0.f);
|
||||
|
||||
scrollView->removed (parent);
|
||||
parent->removeAll (false);
|
||||
}
|
||||
|
||||
TEST_CASE (CListControlTest, PageDown)
|
||||
{
|
||||
constexpr auto rowHeight = 20;
|
||||
constexpr auto numRows = 30;
|
||||
auto parent = makeOwned<CViewContainer> (CRect (0, 0, 1000, 1000));
|
||||
auto listControl = createTestListControl (rowHeight, numRows);
|
||||
auto scrollView = createScrollViewAndEmbedListControl (parent, listControl);
|
||||
listControl->setValue (0.f);
|
||||
auto rect = listControl->getRowRect (numRows);
|
||||
scrollView->makeRectVisible (*rect);
|
||||
|
||||
auto event = makeKeyboardEvent (0, VirtualKey::PageDown);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 15.f);
|
||||
event.consumed.reset ();
|
||||
|
||||
listControl->setValue (14);
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 15.f);
|
||||
event.consumed.reset ();
|
||||
|
||||
listControl->onKeyboardEvent (event);
|
||||
EXPECT (event.consumed == true);
|
||||
EXPECT (listControl->getValue () == 30.f);
|
||||
|
||||
scrollView->removed (parent);
|
||||
parent->removeAll (false);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // VSTGUI
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
// 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 "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (COnOffButtonTest, MouseEvents)
|
||||
{
|
||||
auto b = owned (new COnOffButton (CRect (10, 10, 50, 20)));
|
||||
b->setValue (b->getMin ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Right),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {0., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseCancelEvent (b), EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
}
|
||||
|
||||
TEST_CASE (COnOffButtonTest, KeyEvents)
|
||||
{
|
||||
auto b = owned (new COnOffButton (CRect (10, 10, 50, 20)));
|
||||
b->setValue (b->getMin ());
|
||||
KeyboardEvent event;
|
||||
event.virt = VirtualKey::Return;
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
event.consumed.reset ();
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
event.consumed.reset ();
|
||||
event.virt = VirtualKey::None;
|
||||
event.character = 't';
|
||||
b->onKeyboardEvent (event);
|
||||
EXPECT_FALSE (event.consumed);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+58
@@ -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/coptionmenu.h"
|
||||
#include "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class TestCommandMenuItemTarget
|
||||
: public CommandMenuItemTargetAdapter
|
||||
, public NonAtomicReferenceCounted
|
||||
{
|
||||
};
|
||||
|
||||
TEST_CASE (CCommandMenuItemTest, DescConstructor1)
|
||||
{
|
||||
auto target = makeOwned<TestCommandMenuItemTarget> ();
|
||||
CCommandMenuItem item (
|
||||
{"Title", "k", 0, nullptr, CMenuItem::kNoFlags, target, "CommandCategory", "CommandName"});
|
||||
EXPECT_EQ (item.getTitle (), "Title");
|
||||
EXPECT_EQ (item.getKeycode (), "k");
|
||||
EXPECT_EQ (item.getIcon (), nullptr);
|
||||
EXPECT_EQ (item.getItemTarget (), target);
|
||||
EXPECT_EQ (item.getCommandCategory (), "CommandCategory");
|
||||
EXPECT_EQ (item.getCommandName (), "CommandName");
|
||||
}
|
||||
|
||||
TEST_CASE (CCommandMenuItemTest, DescConstructor2)
|
||||
{
|
||||
auto target = makeOwned<TestCommandMenuItemTarget> ();
|
||||
CCommandMenuItem item ({"Title", 100, target, "CommandCat", "CmdName"});
|
||||
EXPECT_EQ (item.getTitle (), "Title");
|
||||
EXPECT_EQ (item.getItemTarget (), target);
|
||||
EXPECT_EQ (item.getCommandCategory (), "CommandCat");
|
||||
EXPECT_EQ (item.getCommandName (), "CmdName");
|
||||
EXPECT_EQ (item.getTag (), 100);
|
||||
}
|
||||
|
||||
TEST_CASE (CCommandMenuItemTest, DescConstructor3)
|
||||
{
|
||||
auto target = makeOwned<TestCommandMenuItemTarget> ();
|
||||
CCommandMenuItem item ({"MenuItem", target, "CmdCat", "CommandNme"});
|
||||
EXPECT_EQ (item.getTitle (), "MenuItem");
|
||||
EXPECT_EQ (item.getItemTarget (), target);
|
||||
EXPECT_EQ (item.getCommandCategory (), "CmdCat");
|
||||
EXPECT_EQ (item.getCommandName (), "CommandNme");
|
||||
}
|
||||
|
||||
TEST_CASE (COptionMenuTest, GetMaxWhenEmpty)
|
||||
{
|
||||
COptionMenu menu;
|
||||
EXPECT_EQ (menu.getMax (), 0.f);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+446
@@ -0,0 +1,446 @@
|
||||
// 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/cviewcontainer.h"
|
||||
#include "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, AddSegment)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
EXPECT (b.getSegments ().size () == 0);
|
||||
CSegmentButton::Segment s;
|
||||
s.name = "1";
|
||||
b.addSegment (s);
|
||||
EXPECT (b.getSegments ().size () == 1);
|
||||
s.name = "2";
|
||||
b.addSegment (s);
|
||||
EXPECT (b.getSegments ().size () == 2);
|
||||
EXPECT (b.getSegments ()[1].name == "2");
|
||||
s.name = "3";
|
||||
b.addSegment (s, 0);
|
||||
EXPECT (b.getSegments ().size () == 3);
|
||||
EXPECT (b.getSegments ()[0].name == "3");
|
||||
EXPECT (b.getSegments ()[1].name == "1");
|
||||
EXPECT (b.getSegments ()[2].name == "2");
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, InsertSegment)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
CSegmentButton::Segment s;
|
||||
s.name = "0";
|
||||
b.addSegment (std::move (s));
|
||||
s.name = "1";
|
||||
b.addSegment (std::move (s), 0);
|
||||
EXPECT (b.getSegments ()[0].name == "1");
|
||||
EXPECT (b.getSegments ()[1].name == "0");
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, RemoveSegment)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
CSegmentButton::Segment s;
|
||||
s.name = "0";
|
||||
b.addSegment (s);
|
||||
s.name = "1";
|
||||
b.addSegment (s);
|
||||
s.name = "2";
|
||||
b.addSegment (s);
|
||||
s.name = "3";
|
||||
b.addSegment (s);
|
||||
EXPECT (b.getSegments ().size () == 4);
|
||||
b.removeSegment (0);
|
||||
EXPECT (b.getSegments ().size () == 3);
|
||||
EXPECT (b.getSegments ()[0].name == "1");
|
||||
EXPECT (b.getSegments ()[1].name == "2");
|
||||
EXPECT (b.getSegments ()[2].name == "3");
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, SelectedSegment)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
CSegmentButton::Segment s;
|
||||
s.name = "0";
|
||||
b.addSegment (s);
|
||||
s.name = "1";
|
||||
b.addSegment (s);
|
||||
s.name = "2";
|
||||
b.addSegment (s);
|
||||
s.name = "3";
|
||||
b.addSegment (s);
|
||||
b.setSelectedSegment (1);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
b.setSelectedSegment (2);
|
||||
EXPECT (b.getSelectedSegment () == 2);
|
||||
b.setSelectedSegment (3);
|
||||
EXPECT (b.getSelectedSegment () == 3);
|
||||
b.setSelectedSegment (4);
|
||||
EXPECT (b.getSelectedSegment () == 3);
|
||||
b.setSelectedSegment (0);
|
||||
EXPECT (b.getSelectedSegment () == 0);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, RightKeyEvent)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
CSegmentButton::Segment s;
|
||||
s.name = "0";
|
||||
b.addSegment (s);
|
||||
s.name = "1";
|
||||
b.addSegment (s);
|
||||
s.name = "2";
|
||||
b.addSegment (s);
|
||||
|
||||
b.setStyle (CSegmentButton::Style::kHorizontal);
|
||||
b.setSelectedSegment (0);
|
||||
|
||||
KeyboardEvent event;
|
||||
event.virt = VirtualKey::Right;
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 2);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 2);
|
||||
|
||||
b.setSelectedSegment (1);
|
||||
b.setStyle (CSegmentButton::Style::kVertical);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, LeftKeyEvent)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
CSegmentButton::Segment s;
|
||||
s.name = "0";
|
||||
b.addSegment (s);
|
||||
s.name = "1";
|
||||
b.addSegment (s);
|
||||
s.name = "2";
|
||||
b.addSegment (s);
|
||||
|
||||
b.setStyle (CSegmentButton::Style::kHorizontal);
|
||||
b.setSelectedSegment (2);
|
||||
|
||||
KeyboardEvent event;
|
||||
event.virt = VirtualKey::Left;
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 0);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 0);
|
||||
|
||||
b.setSelectedSegment (1);
|
||||
b.setStyle (CSegmentButton::Style::kVertical);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, DownKeyEvent)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
CSegmentButton::Segment s;
|
||||
s.name = "0";
|
||||
b.addSegment (s);
|
||||
s.name = "1";
|
||||
b.addSegment (s);
|
||||
s.name = "2";
|
||||
b.addSegment (s);
|
||||
|
||||
b.setStyle (CSegmentButton::Style::kVertical);
|
||||
b.setSelectedSegment (0);
|
||||
|
||||
KeyboardEvent event;
|
||||
event.virt = VirtualKey::Down;
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 2);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 2);
|
||||
|
||||
b.setSelectedSegment (1);
|
||||
b.setStyle (CSegmentButton::Style::kHorizontal);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, UpKeyEvent)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
CSegmentButton::Segment s;
|
||||
s.name = "0";
|
||||
b.addSegment (s);
|
||||
s.name = "1";
|
||||
b.addSegment (s);
|
||||
s.name = "2";
|
||||
b.addSegment (s);
|
||||
|
||||
b.setStyle (CSegmentButton::Style::kVertical);
|
||||
b.setSelectedSegment (2);
|
||||
KeyboardEvent event;
|
||||
event.virt = VirtualKey::Up;
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 0);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 0);
|
||||
|
||||
b.setSelectedSegment (1);
|
||||
b.setStyle (CSegmentButton::Style::kHorizontal);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
event.consumed.reset ();
|
||||
b.onKeyboardEvent (event);
|
||||
EXPECT_TRUE (event.consumed);
|
||||
EXPECT (b.getSelectedSegment () == 1);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, HorizontalSegmentSizeCalculation)
|
||||
{
|
||||
const auto numSegments = 5;
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto b = new CSegmentButton (r);
|
||||
b->setStyle (CSegmentButton::Style::kHorizontal);
|
||||
for (auto i = 0; i < numSegments; ++i)
|
||||
b->addSegment ({});
|
||||
for (const auto& s : b->getSegments ())
|
||||
EXPECT (s.rect == CRect (0, 0, 0, 0));
|
||||
auto root = owned (new CViewContainer (r));
|
||||
auto parent = new CViewContainer (r);
|
||||
root->addView (parent);
|
||||
parent->addView (b);
|
||||
parent->attached (root);
|
||||
EXPECT (b->getSegments ()[0].rect == CRect (0, 0, 20, 100));
|
||||
EXPECT (b->getSegments ()[1].rect == CRect (20, 0, 40, 100));
|
||||
EXPECT (b->getSegments ()[2].rect == CRect (40, 0, 60, 100));
|
||||
EXPECT (b->getSegments ()[3].rect == CRect (60, 0, 80, 100));
|
||||
EXPECT (b->getSegments ()[4].rect == CRect (80, 0, 100, 100));
|
||||
parent->removed (root);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, VerticalSegmentSizeCalculation)
|
||||
{
|
||||
const auto numSegments = 5;
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto b = new CSegmentButton (r);
|
||||
b->setStyle (CSegmentButton::Style::kVertical);
|
||||
for (auto i = 0; i < numSegments; ++i)
|
||||
b->addSegment ({});
|
||||
for (const auto& s : b->getSegments ())
|
||||
EXPECT (s.rect == CRect (0, 0, 0, 0));
|
||||
auto root = owned (new CViewContainer (r));
|
||||
auto parent = new CViewContainer (r);
|
||||
root->addView (parent);
|
||||
parent->addView (b);
|
||||
parent->attached (root);
|
||||
EXPECT (b->getSegments ()[0].rect == CRect (0, 0, 100, 20));
|
||||
EXPECT (b->getSegments ()[1].rect == CRect (0, 20, 100, 40));
|
||||
EXPECT (b->getSegments ()[2].rect == CRect (0, 40, 100, 60));
|
||||
EXPECT (b->getSegments ()[3].rect == CRect (0, 60, 100, 80));
|
||||
EXPECT (b->getSegments ()[4].rect == CRect (0, 80, 100, 100));
|
||||
parent->removed (root);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, UpdateViewSize)
|
||||
{
|
||||
const auto numSegments = 5;
|
||||
auto b = new CSegmentButton (CRect (0, 0, 50, 100));
|
||||
b->setStyle (CSegmentButton::Style::kHorizontal);
|
||||
for (auto i = 0; i < numSegments; ++i)
|
||||
b->addSegment ({});
|
||||
for (const auto& s : b->getSegments ())
|
||||
EXPECT (s.rect == CRect (0, 0, 0, 0));
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto root = owned (new CViewContainer (r));
|
||||
auto parent = new CViewContainer (r);
|
||||
root->addView (parent);
|
||||
parent->addView (b);
|
||||
parent->attached (root);
|
||||
EXPECT (b->getSegments ()[0].rect == CRect (0, 0, 10, 100));
|
||||
EXPECT (b->getSegments ()[1].rect == CRect (10, 0, 20, 100));
|
||||
EXPECT (b->getSegments ()[2].rect == CRect (20, 0, 30, 100));
|
||||
EXPECT (b->getSegments ()[3].rect == CRect (30, 0, 40, 100));
|
||||
EXPECT (b->getSegments ()[4].rect == CRect (40, 0, 50, 100));
|
||||
b->setViewSize (r);
|
||||
EXPECT (b->getSegments ()[0].rect == CRect (0, 0, 20, 100));
|
||||
EXPECT (b->getSegments ()[1].rect == CRect (20, 0, 40, 100));
|
||||
EXPECT (b->getSegments ()[2].rect == CRect (40, 0, 60, 100));
|
||||
EXPECT (b->getSegments ()[3].rect == CRect (60, 0, 80, 100));
|
||||
EXPECT (b->getSegments ()[4].rect == CRect (80, 0, 100, 100));
|
||||
parent->removed (root);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, MouseDownEvent)
|
||||
{
|
||||
const auto numSegments = 5;
|
||||
CRect r (0, 0, 100, 100);
|
||||
auto b = new CSegmentButton (r);
|
||||
b->setStyle (CSegmentButton::Style::kHorizontal);
|
||||
for (auto i = 0; i < numSegments; ++i)
|
||||
b->addSegment ({});
|
||||
for (const auto& s : b->getSegments ())
|
||||
EXPECT (s.rect == CRect (0, 0, 0, 0));
|
||||
auto root = owned (new CViewContainer (r));
|
||||
auto parent = new CViewContainer (r);
|
||||
root->addView (parent);
|
||||
parent->addView (b);
|
||||
parent->attached (root);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {0., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_EQ (b->getSelectedSegment (), 0);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {25., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_EQ (b->getSelectedSegment (), 1);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {45., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_EQ (b->getSelectedSegment (), 2);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {65., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_EQ (b->getSelectedSegment (), 3);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {85., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_EQ (b->getSelectedSegment (), 4);
|
||||
|
||||
parent->removed (root);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, MouseDownEventWithManySegments)
|
||||
{
|
||||
// Create segment button with 32 segments and attach it
|
||||
const auto numSegments = 32;
|
||||
CRect r (0, 0, 20 * numSegments, 100);
|
||||
auto b = new CSegmentButton (r);
|
||||
b->setStyle (CSegmentButton::Style::kHorizontal);
|
||||
for (auto i = 0; i < numSegments; ++i)
|
||||
b->addSegment ({});
|
||||
for (const auto& s : b->getSegments ())
|
||||
EXPECT_EQ (s.rect, CRect (0, 0, 0, 0));
|
||||
auto root = owned (new CViewContainer (r));
|
||||
auto parent = new CViewContainer (r);
|
||||
root->addView (parent);
|
||||
parent->addView (b);
|
||||
parent->attached (root);
|
||||
|
||||
// Select the e.g. 20th segment
|
||||
constexpr auto kSelectedSegment = 20;
|
||||
CPoint p (20 * kSelectedSegment + 5, 0);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, p, MouseButton::Left),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_EQ (b->getSelectedSegment (), kSelectedSegment);
|
||||
|
||||
parent->removed (root);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, MouseDownEventOnLastSegment)
|
||||
{
|
||||
// Create segment button with 31 segments and attach it.
|
||||
// 31 segments causing rounding errors inside segment button.
|
||||
const auto numSegments = 31;
|
||||
CRect r (0, 0, 20 * numSegments, 100);
|
||||
auto b = new CSegmentButton (r);
|
||||
b->setStyle (CSegmentButton::Style::kHorizontal);
|
||||
for (auto i = 0; i < numSegments; ++i)
|
||||
b->addSegment ({});
|
||||
for (const auto& s : b->getSegments ())
|
||||
EXPECT_EQ (s.rect, CRect (0, 0, 0, 0));
|
||||
auto root = owned (new CViewContainer (r));
|
||||
auto parent = new CViewContainer (r);
|
||||
root->addView (parent);
|
||||
parent->addView (b);
|
||||
parent->attached (root);
|
||||
|
||||
// Select the last segment
|
||||
constexpr auto kSelectedSegment = numSegments - 1;
|
||||
CPoint p (0, 0);
|
||||
p (20 * kSelectedSegment + 5, 0);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, p, MouseButton::Left),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_EQ (b->getSelectedSegment (), kSelectedSegment);
|
||||
|
||||
parent->removed (root);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, FocusPathSetting)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
EXPECT (b.drawFocusOnTop () == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, MultiSelection)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
b.setSelectionMode (CSegmentButton::SelectionMode::kMultiple);
|
||||
b.addSegment ({});
|
||||
b.addSegment ({});
|
||||
b.addSegment ({});
|
||||
b.selectSegment (0, true);
|
||||
b.selectSegment (1, false);
|
||||
b.selectSegment (2, true);
|
||||
EXPECT (b.isSegmentSelected (0) == true);
|
||||
EXPECT (b.isSegmentSelected (1) == false);
|
||||
EXPECT (b.isSegmentSelected (2) == true);
|
||||
}
|
||||
|
||||
TEST_CASE (CSegmentButtonTest, MultiSelectionMaxEntries)
|
||||
{
|
||||
CSegmentButton b (CRect (0, 0, 10, 10));
|
||||
b.setSelectionMode (CSegmentButton::SelectionMode::kMultiple);
|
||||
CSegmentButton::Segment s;
|
||||
for (auto i = 0; i < 32; ++i)
|
||||
{
|
||||
EXPECT (b.addSegment (s) == true);
|
||||
}
|
||||
EXPECT (b.addSegment (s) == false);
|
||||
EXPECT (b.addSegment (std::move (s)) == false);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
// 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 "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CTextButtonTest, MouseEventsKickStyle)
|
||||
{
|
||||
auto b = owned (new CTextButton (CRect (10, 10, 50, 20)));
|
||||
b->setStyle (CTextButton::kKickStyle);
|
||||
b->setValue (b->getMin ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Right),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {0., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseCancelEvent (b), EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::NotHandled);
|
||||
}
|
||||
|
||||
TEST_CASE (CTextButtonTest, MouseEventsOnOffStyle)
|
||||
{
|
||||
auto b = owned (new CTextButton (CRect (10, 10, 50, 20)));
|
||||
b->setStyle (CTextButton::kOnOffStyle);
|
||||
b->setValue (b->getMin ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Right),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {0., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (b, {0., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (b->isEditing ());
|
||||
EXPECT_EQ (dispatchMouseCancelEvent (b), EventConsumeState::Handled);
|
||||
EXPECT_FALSE (b->isEditing ());
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (b, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::NotHandled);
|
||||
}
|
||||
|
||||
TEST_CASE (CTextButtonTest, KeyEvents)
|
||||
{
|
||||
auto b = owned (new CTextButton (CRect (10, 10, 50, 20)));
|
||||
b->setStyle (CTextButton::kOnOffStyle);
|
||||
b->setValue (b->getMin ());
|
||||
KeyboardEvent retEvent;
|
||||
retEvent.virt = VirtualKey::Return;
|
||||
b->onKeyboardEvent (retEvent);
|
||||
EXPECT_TRUE (retEvent.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMax ());
|
||||
retEvent.consumed.reset ();
|
||||
b->onKeyboardEvent (retEvent);
|
||||
EXPECT_TRUE (retEvent.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
KeyboardEvent charEvent;
|
||||
charEvent.character = 't';
|
||||
b->onKeyboardEvent (charEvent);
|
||||
EXPECT_FALSE (charEvent.consumed);
|
||||
|
||||
b->setStyle (CTextButton::kKickStyle);
|
||||
retEvent.consumed.reset ();
|
||||
b->onKeyboardEvent (retEvent);
|
||||
EXPECT_TRUE (retEvent.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
retEvent.consumed.reset ();
|
||||
b->onKeyboardEvent (retEvent);
|
||||
EXPECT_TRUE (retEvent.consumed);
|
||||
EXPECT_EQ (b->getValue (), b->getMin ());
|
||||
|
||||
KeyboardEvent upEvent;
|
||||
upEvent.type = EventType::KeyUp;
|
||||
upEvent.virt = VirtualKey::Return;
|
||||
b->onKeyboardEvent (upEvent);
|
||||
EXPECT_FALSE (upEvent.consumed);
|
||||
}
|
||||
|
||||
TEST_CASE (CTextButtonTest, FocusPathSetting)
|
||||
{
|
||||
auto b = owned (new CTextButton (CRect (10, 10, 50, 20)));
|
||||
EXPECT_FALSE (b->drawFocusOnTop ());
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
// 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 "../../unittests.h"
|
||||
#include "../eventhelpers.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CXYPadTest, valueCalculation)
|
||||
{
|
||||
auto value = CXYPad::calculateValue (0.f, 0.f);
|
||||
float x = 1.f;
|
||||
float y = 1.f;
|
||||
CXYPad::calculateXY (value, x, y);
|
||||
EXPECT (x == 0.f);
|
||||
EXPECT (y == 0.f);
|
||||
value = CXYPad::calculateValue (1.f, 0.f);
|
||||
CXYPad::calculateXY (value, x, y);
|
||||
EXPECT (x == 1.f);
|
||||
EXPECT (y == 0.f);
|
||||
value = CXYPad::calculateValue (0.f, 1.f);
|
||||
CXYPad::calculateXY (value, x, y);
|
||||
EXPECT (x == 0.f);
|
||||
EXPECT (y == 1.f);
|
||||
value = CXYPad::calculateValue (0.5f, 0.5f);
|
||||
CXYPad::calculateXY (value, x, y);
|
||||
EXPECT (x == 0.5f);
|
||||
EXPECT (y == 0.5f);
|
||||
value = CXYPad::calculateValue (0.25f, 0.25f);
|
||||
CXYPad::calculateXY (value, x, y);
|
||||
EXPECT (x == 0.25f);
|
||||
EXPECT (y == 0.25f);
|
||||
}
|
||||
|
||||
TEST_CASE (CXYPadTest, MouseLeftDownInteraction)
|
||||
{
|
||||
CXYPad pad (CRect (0, 0, 100, 100));
|
||||
pad.setRoundRectRadius (0.f);
|
||||
|
||||
dispatchMouseEvent<MouseDownEvent> (&pad, {0., 0.}, MouseButton::Left);
|
||||
dispatchMouseEvent<MouseMoveEvent> (&pad, {10., 10.}, MouseButton::Left);
|
||||
float x = 1.f;
|
||||
float y = 1.f;
|
||||
pad.calculateXY (pad.getValue (), x, y);
|
||||
EXPECT (x == 0.1f);
|
||||
EXPECT (y == 0.1f);
|
||||
dispatchMouseEvent<MouseMoveEvent> (&pad, {110., 110.}, MouseButton::Left);
|
||||
pad.calculateXY (pad.getValue (), x, y);
|
||||
EXPECT (x == 1.f);
|
||||
EXPECT (y == 1.f);
|
||||
dispatchMouseEvent<MouseMoveEvent> (&pad, {-10., -10.}, MouseButton::Left);
|
||||
pad.calculateXY (pad.getValue (), x, y);
|
||||
EXPECT (x == 0.f);
|
||||
EXPECT (y == 0.f);
|
||||
dispatchMouseEvent<MouseUpEvent> (&pad, {-10., -10.}, MouseButton::Left);
|
||||
EXPECT_FALSE(pad.isEditing ());
|
||||
}
|
||||
|
||||
TEST_CASE (CXYPadTest, CancelMouseInteraction)
|
||||
{
|
||||
CXYPad pad (CRect (0, 0, 100, 100));
|
||||
|
||||
float startX {-1.f};
|
||||
float startY {-1.f};
|
||||
pad.calculateXY (pad.getValue (), startX, startY);
|
||||
dispatchMouseEvent<MouseDownEvent> (&pad, {0., 0.}, MouseButton::Left);
|
||||
dispatchMouseEvent<MouseMoveEvent> (&pad, {10., 10.}, MouseButton::Left);
|
||||
float x {-1.f};
|
||||
float y {-1.f};
|
||||
pad.calculateXY (pad.getValue (), x, y);
|
||||
EXPECT (startX != x);
|
||||
EXPECT (startY != y);
|
||||
dispatchMouseCancelEvent (&pad);
|
||||
pad.calculateXY (pad.getValue (), x, y);
|
||||
EXPECT (startX == x);
|
||||
EXPECT (startY == y);
|
||||
}
|
||||
|
||||
TEST_CASE (CXYPadTest, OtherMouseInteraction)
|
||||
{
|
||||
CXYPad pad (CRect (0, 0, 100, 100));
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (&pad, {0., 0.}, MouseButton::Right),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (&pad, {0., 0.}, MouseButton::Right),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (&pad, {0., 0.}, MouseButton::Right),
|
||||
EventConsumeState::NotHandled);
|
||||
}
|
||||
|
||||
TEST_CASE (CXYPadTest, StopTrackingOnMouseExit)
|
||||
{
|
||||
CXYPad pad (CRect (0, 0, 100, 100));
|
||||
pad.setStopTrackingOnMouseExit (true);
|
||||
pad.setRoundRectRadius (0.f);
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (&pad, {0., 0.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (pad.isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (&pad, {50., 50.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (pad.isEditing ());
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (&pad, {150., 150.}, MouseButton::Left),
|
||||
EventConsumeState::Handled | MouseDownUpMoveEvent::IgnoreFollowUpEventsMask);
|
||||
EXPECT_FALSE (pad.isEditing ());
|
||||
}
|
||||
|
||||
TEST_CASE (CXYPadTest, MouseWheel)
|
||||
{
|
||||
CXYPad pad (CRect (0, 0, 100, 100));
|
||||
float x = 1.f;
|
||||
float y = 1.f;
|
||||
CXYPad::calculateXY (pad.getValue (), x, y);
|
||||
EXPECT (x == 0.f && y == 0.f);
|
||||
dispatchMouseWheelEvent (&pad, {1., 1.}, 1., 0.);
|
||||
CXYPad::calculateXY (pad.getValue (), x, y);
|
||||
EXPECT (x == pad.getWheelInc () && y == 0.f);
|
||||
dispatchMouseWheelEvent (&pad, {1., 1.}, 0., 1.);
|
||||
CXYPad::calculateXY (pad.getValue (), x, y);
|
||||
EXPECT (x == pad.getWheelInc () && y == pad.getWheelInc ());
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,97 @@
|
||||
// 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 "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CPointTest, Unequal)
|
||||
{
|
||||
EXPECT (CPoint (0, 0) != CPoint (1, 1));
|
||||
EXPECT (CPoint (0, 0) != CPoint (0, 1));
|
||||
EXPECT (CPoint (0, 0) != CPoint (1, 0));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, Equal)
|
||||
{
|
||||
EXPECT (CPoint (0, 0) == CPoint (0, 0));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, OperatorAddAssign)
|
||||
{
|
||||
CPoint p (1, 1);
|
||||
p += CPoint (1, 1);
|
||||
EXPECT (p == CPoint (2, 2));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, OperatorSubtractAssign)
|
||||
{
|
||||
CPoint p (2, 2);
|
||||
p -= CPoint (1, 1);
|
||||
EXPECT (p == CPoint (1, 1));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, OperatorAdd)
|
||||
{
|
||||
CPoint p (2, 2);
|
||||
auto p2 = p + CPoint (1, 1);
|
||||
EXPECT (p2 == CPoint (3, 3));
|
||||
EXPECT (p == CPoint (2, 2));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, OperatorSubtract)
|
||||
{
|
||||
CPoint p (2, 2);
|
||||
auto p2 = p - CPoint (1, 1);
|
||||
EXPECT (p2 == CPoint (1, 1));
|
||||
EXPECT (p == CPoint (2, 2));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, OperatorInverse)
|
||||
{
|
||||
CPoint p (2, 2);
|
||||
auto p2 = -p;
|
||||
EXPECT (p2 == CPoint (-2, -2));
|
||||
EXPECT (p == CPoint (2, 2));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, OffsetCoords)
|
||||
{
|
||||
CPoint p (1, 2);
|
||||
p.offset (1, 2);
|
||||
EXPECT (p == CPoint (2, 4));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, OffsetPoint)
|
||||
{
|
||||
CPoint p (1, 2);
|
||||
p.offset (CPoint (2, 3));
|
||||
EXPECT (p == CPoint (3, 5));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, OffsetInverse)
|
||||
{
|
||||
CPoint p (5, 3);
|
||||
p.offsetInverse (CPoint (2, 1));
|
||||
EXPECT (p == CPoint (3, 2));
|
||||
}
|
||||
|
||||
TEST_CASE (CPointTest, MakeIntegral)
|
||||
{
|
||||
CPoint p (5.3, 4.2);
|
||||
p.makeIntegral ();
|
||||
EXPECT (p == CPoint (5, 4));
|
||||
p (5.5, 4.5);
|
||||
p.makeIntegral ();
|
||||
EXPECT (p == CPoint (6, 5));
|
||||
p (5.9, 4.1);
|
||||
p.makeIntegral ();
|
||||
EXPECT (p == CPoint (6, 4));
|
||||
p (5.1, 4.501);
|
||||
p.makeIntegral ();
|
||||
EXPECT (p == CPoint (5, 5));
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,225 @@
|
||||
// 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/crect.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (CRectTest, MakeIntegral)
|
||||
{
|
||||
CRect r (0.2, 0.5, 10.8, 12.1);
|
||||
r.makeIntegral ();
|
||||
EXPECT (r.left == 0.0)
|
||||
EXPECT (r.top == 0.0)
|
||||
EXPECT (r.right == 11.0)
|
||||
EXPECT (r.bottom == 13.0)
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, GetCenter)
|
||||
{
|
||||
CRect r (0, 0, 50, 50);
|
||||
CPoint p = r.getCenter ();
|
||||
EXPECT (p.x == 25 && p.y == 25)
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, CenterInside)
|
||||
{
|
||||
CRect r (0, 0, 500, 500);
|
||||
CRect r2 (0, 0, 10, 10);
|
||||
r2.centerInside (r);
|
||||
EXPECT (r2.left == 245 && r2.top == 245 && r2.getWidth () == 10 && r2.getHeight () == 10)
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, PointInside)
|
||||
{
|
||||
CRect r (0, 0, 250, 250);
|
||||
CPoint p (50, 50);
|
||||
EXPECT (r.pointInside (p))
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, PointNotInside)
|
||||
{
|
||||
CRect r (0, 0, 250, 250);
|
||||
CPoint p (250, 50);
|
||||
EXPECT (r.pointInside (p) == false)
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, RectOverlap)
|
||||
{
|
||||
CRect r (50, 50, 100, 100);
|
||||
CRect r2 (90, 90, 120, 120);
|
||||
EXPECT (r.rectOverlap (r2))
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, RectNotOverlap)
|
||||
{
|
||||
CRect r (50, 50, 100, 100);
|
||||
CRect r2 (100, 101, 120, 120);
|
||||
CRect r3 (101, 100, 120, 120);
|
||||
CRect r4 (0, 0, 40, 40);
|
||||
CRect r5 (51, 51, 100, 40);
|
||||
EXPECT (r.rectOverlap (r2) == false)
|
||||
EXPECT (r.rectOverlap (r3) == false)
|
||||
EXPECT (r.rectOverlap (r4) == false)
|
||||
EXPECT (r.rectOverlap (r5) == false)
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Bound)
|
||||
{
|
||||
CRect r (50, 50, 100, 100);
|
||||
CRect r2 (90, 90, 200, 200);
|
||||
r.bound (r2);
|
||||
EXPECT (r.left == 90 && r.top == 90 && r.right == 100 && r.bottom == 100)
|
||||
r (0, 0, 80, 80);
|
||||
r.bound (r2);
|
||||
EXPECT (r.left == 90 && r.top == 90 && r.right == 90 && r.bottom == 90)
|
||||
r (0, 0, 280, 280);
|
||||
r.bound (r2);
|
||||
EXPECT (r.left == 90 && r.top == 90 && r.right == 200 && r.bottom == 200)
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Unite)
|
||||
{
|
||||
CRect r (20, 20, 40, 40);
|
||||
CRect r2 (40, 40, 80, 80);
|
||||
r.unite (r2);
|
||||
EXPECT (r.left == 20 && r.top == 20 && r.right == 80 && r.bottom == 80)
|
||||
r (50, 50, 120, 120);
|
||||
r.unite (r2);
|
||||
EXPECT (r.left == 40 && r.top == 40 && r.right == 120 && r.bottom == 120)
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, SetWidth)
|
||||
{
|
||||
CRect r (0., 0., 0., 0.);
|
||||
EXPECT (r.getWidth () == 0.);
|
||||
r.setWidth (100.);
|
||||
EXPECT (r.getWidth () == 100.);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, setHeight)
|
||||
{
|
||||
CRect r (0., 0., 0., 0.);
|
||||
EXPECT (r.getHeight () == 0.);
|
||||
r.setHeight (100.);
|
||||
EXPECT (r.getHeight () == 100.);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Offset)
|
||||
{
|
||||
CRect r (0, 0, 10, 10);
|
||||
r.offset (CPoint (5, 5));
|
||||
EXPECT (r.left == 5 && r.top == 5 && r.right == 15 && r.bottom == 15);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, OffsetInverse)
|
||||
{
|
||||
CRect r (10, 10, 20, 20);
|
||||
r.offsetInverse (CPoint (5, 5));
|
||||
EXPECT (r.left == 5 && r.top == 5 && r.right == 15 && r.bottom == 15);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Extend)
|
||||
{
|
||||
CRect r (5, 5, 10, 10);
|
||||
r.extend (CPoint (5, 5));
|
||||
EXPECT (r.left == 0 && r.top == 0 && r.right == 15 && r.bottom == 15);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Assign4CoordOperator)
|
||||
{
|
||||
CRect r;
|
||||
r (0, 0, 15, 15);
|
||||
EXPECT (r.left == 0 && r.top == 0 && r.right == 15 && r.bottom == 15);
|
||||
r (15, 15, 0, 0);
|
||||
EXPECT (r.left == 0 && r.top == 0 && r.right == 15 && r.bottom == 15);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, OriginSizeConstructor)
|
||||
{
|
||||
CRect r (CPoint (10, 10), CPoint (10, 10));
|
||||
EXPECT (r.left == 10 && r.top == 10 && r.right == 20 && r.bottom == 20);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Inset)
|
||||
{
|
||||
CRect r (0., 0., 100., 100.);
|
||||
r.inset (CPoint (5, 5));
|
||||
EXPECT (r.left == 5.);
|
||||
EXPECT (r.top == 5.);
|
||||
EXPECT (r.right == 95.);
|
||||
EXPECT (r.bottom == 95.);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Normalize)
|
||||
{
|
||||
CRect r (50, 50, 0, 0);
|
||||
r.normalize ();
|
||||
EXPECT (r.left == 0 && r.top == 0 && r.right == 50 && r.bottom == 50);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Originize)
|
||||
{
|
||||
CRect r (50, 50, 150, 150);
|
||||
r.originize ();
|
||||
EXPECT (r.left == 0 && r.top == 0 && r.right == 100 && r.bottom == 100);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, MoveTo)
|
||||
{
|
||||
CRect r (0, 0, 20, 20);
|
||||
r.moveTo (CPoint (20, 20));
|
||||
EXPECT (r.left == 20 && r.top == 20 && r.right == 40 && r.bottom == 40);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, Corners)
|
||||
{
|
||||
CRect r (10, 10, 20, 20);
|
||||
auto topLeft = r.getTopLeft ();
|
||||
EXPECT (topLeft.x == 10 && topLeft.y == 10);
|
||||
auto topRight = r.getTopRight ();
|
||||
EXPECT (topRight.x == 20 && topRight.y == 10);
|
||||
auto bottomLeft = r.getBottomLeft ();
|
||||
EXPECT (bottomLeft.x == 10 && bottomLeft.y == 20);
|
||||
auto bottomRight = r.getBottomRight ();
|
||||
EXPECT (bottomRight.x == 20 && bottomRight.y == 20);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, SetCorners)
|
||||
{
|
||||
CRect r (0, 0, 0, 0);
|
||||
r.setTopLeft (CPoint (10, 10));
|
||||
EXPECT (r.left == 10 && r.top == 10);
|
||||
r.setTopRight (CPoint (10, 10));
|
||||
EXPECT (r.right == 10 && r.top == 10);
|
||||
r.setBottomLeft (CPoint (10, 10));
|
||||
EXPECT (r.left == 10 && r.bottom == 10);
|
||||
r.setBottomRight (CPoint (10, 10));
|
||||
EXPECT (r.right == 10 && r.bottom == 10);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, GetSize)
|
||||
{
|
||||
CRect r (20, 20, 22, 22);
|
||||
auto s = r.getSize ();
|
||||
EXPECT (s.x == 2 && s.y == 2);
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, IsEmpty)
|
||||
{
|
||||
CRect r (1, 1, 1, 2);
|
||||
EXPECT (r.isEmpty ());
|
||||
r (1, 1, 2, 1);
|
||||
EXPECT (r.isEmpty ());
|
||||
}
|
||||
|
||||
TEST_CASE (CRectTest, OperatorEqual)
|
||||
{
|
||||
CRect r1 (0, 1, 2, 3);
|
||||
CRect r2 (0, 1, 2, 3);
|
||||
EXPECT (r1 == r2);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
// 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 "../unittests.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
using Rects = std::vector<CRect>;
|
||||
|
||||
static const CRect templateSize (0., 0., 100., 100.);
|
||||
static const CRect layoutSize (0., 0., 80., 80.);
|
||||
|
||||
// clang-format off
|
||||
static const Rects childrenDefaultSizes = {
|
||||
{0., 0., 10., 10.},
|
||||
{0., 0., 20., 20.},
|
||||
{0., 0., 30., 30.}
|
||||
};
|
||||
|
||||
using ExpectedResults = std::map<CRowColumnView::LayoutStyle, Rects>;
|
||||
|
||||
static const ExpectedResults kRowLayoutChildrenResultSizes = {
|
||||
{
|
||||
CRowColumnView::kTopLeft, {
|
||||
{0., 0., 10., 10.},
|
||||
{0., 10., 20., 30.},
|
||||
{0., 30., 30., 60.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kTopCenter, {
|
||||
{35., 0., 45., 10.},
|
||||
{30., 10., 50., 30.},
|
||||
{25., 30., 55., 60.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kTopRight, {
|
||||
{70., 0., 80., 10.},
|
||||
{60., 10., 80., 30.},
|
||||
{50., 30., 80., 60.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kMiddleLeft, {
|
||||
{0., 10., 10., 20.},
|
||||
{0., 20., 20., 40.},
|
||||
{0., 40., 30., 70.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kMiddleCenter, {
|
||||
{35., 10., 45., 20.},
|
||||
{30., 20., 50., 40.},
|
||||
{25., 40., 55., 70.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kMiddleRight, {
|
||||
{70., 10., 80., 20.},
|
||||
{60., 20., 80., 40.},
|
||||
{50., 40., 80., 70.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kBottomLeft, {
|
||||
{0., 20., 10., 30.},
|
||||
{0., 30., 20., 50.},
|
||||
{0., 50., 30., 80.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kBottomCenter, {
|
||||
{35., 20., 45., 30.},
|
||||
{30., 30., 50., 50.},
|
||||
{25., 50., 55., 80.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kBottomRight, {
|
||||
{70., 20., 80., 30.},
|
||||
{60., 30., 80., 50.},
|
||||
{50., 50., 80., 80.}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const ExpectedResults kColumnLayoutChildrenResultSizes = {
|
||||
{
|
||||
CRowColumnView::kTopLeft, {
|
||||
{0., 0., 10., 10.},
|
||||
{10., 0., 30., 20.},
|
||||
{30., 0., 60., 30.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kTopCenter, {
|
||||
{10., 0., 20., 10.},
|
||||
{20., 0., 40., 20.},
|
||||
{40., 0., 70., 30.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kTopRight, {
|
||||
{20., 0., 30., 10.},
|
||||
{30., 0., 50., 20.},
|
||||
{50., 0., 80., 30.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kMiddleLeft, {
|
||||
{0., 35., 10., 45.},
|
||||
{10., 30., 30., 50.},
|
||||
{30., 25., 60., 55.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kMiddleCenter, {
|
||||
{10., 35., 20., 45.},
|
||||
{20., 30., 40., 50.},
|
||||
{40., 25., 70., 55.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kMiddleRight, {
|
||||
{20., 35., 30., 45.},
|
||||
{30., 30., 50., 50.},
|
||||
{50., 25., 80., 55.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kBottomLeft, {
|
||||
{0., 70., 10., 80.},
|
||||
{10., 60., 30., 80.},
|
||||
{30., 50., 60., 80.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kBottomCenter, {
|
||||
{10., 70., 20., 80.},
|
||||
{20., 60., 40., 80.},
|
||||
{40., 50., 70., 80.}
|
||||
}
|
||||
},
|
||||
{
|
||||
CRowColumnView::kBottomRight, {
|
||||
{20., 70., 30., 80.},
|
||||
{30., 60., 50., 80.},
|
||||
{50., 50., 80., 80.}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const ExpectedResults kRowLayoutChildrenResultSizesWithSpacing = {
|
||||
{
|
||||
CRowColumnView::kMiddleCenter, {
|
||||
{35., 6., 45., 16.},
|
||||
{30., 20., 50., 40.},
|
||||
{25., 44., 55., 74.}
|
||||
}
|
||||
}
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
struct TestData
|
||||
{
|
||||
CRowColumnView::LayoutStyle layoutStyle = CRowColumnView::LayoutStyle::kTopLeft;
|
||||
CRowColumnView::Style style = CRowColumnView::Style::kRowStyle;
|
||||
double spacing = 0.;
|
||||
ExpectedResults expected;
|
||||
};
|
||||
|
||||
auto testWithLayoutStyle (const TestData& testData) -> void
|
||||
{
|
||||
const auto& expected = testData.expected.find (testData.layoutStyle)->second;
|
||||
auto rowColumnView = owned (new CRowColumnView (layoutSize));
|
||||
rowColumnView->setStyle (testData.style);
|
||||
rowColumnView->setLayoutStyle (testData.layoutStyle);
|
||||
rowColumnView->setSpacing (testData.spacing);
|
||||
|
||||
for (auto& rect : childrenDefaultSizes)
|
||||
{
|
||||
auto child = new CView (rect);
|
||||
rowColumnView->CViewContainer::addView (child);
|
||||
rowColumnView->layoutViews ();
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
rowColumnView->forEachChild ([&] (CView* child) {
|
||||
const auto& childrenResults = testData.expected.find (testData.layoutStyle);
|
||||
auto viewSize = child->getViewSize ();
|
||||
EXPECT (viewSize == expected.at (i))
|
||||
i++;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutTopLeftStyle)
|
||||
{
|
||||
testWithLayoutStyle (
|
||||
{CRowColumnView::kTopLeft, CRowColumnView::kRowStyle, 0., kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutTopCenterStyle)
|
||||
{
|
||||
testWithLayoutStyle (
|
||||
{CRowColumnView::kTopCenter, CRowColumnView::kRowStyle, 0., kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutTopRightStyle)
|
||||
{
|
||||
testWithLayoutStyle (
|
||||
{CRowColumnView::kTopRight, CRowColumnView::kRowStyle, 0., kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutMiddleLeftStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kMiddleLeft, CRowColumnView::kRowStyle, 0.,
|
||||
kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutMiddleCenterStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kMiddleCenter, CRowColumnView::kRowStyle, 0.,
|
||||
kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutMiddleRightStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kMiddleRight, CRowColumnView::kRowStyle, 0.,
|
||||
kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutBottomLeftStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kBottomLeft, CRowColumnView::kRowStyle, 0.,
|
||||
kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutBottomCenterStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kBottomCenter, CRowColumnView::kRowStyle, 0.,
|
||||
kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutBottomRightStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kBottomRight, CRowColumnView::kRowStyle, 0.,
|
||||
kRowLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutTopLeftStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kTopLeft, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutTopCenterStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kTopCenter, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutTopRightStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kTopRight, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutMiddleLeftStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kMiddleLeft, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutMiddleCenterStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kMiddleCenter, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutMiddleRightStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kMiddleRight, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutBottomLeftStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kBottomLeft, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutBottomCenterStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kBottomCenter, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, ColumnLayoutBottomRightStyle)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kBottomRight, CRowColumnView::kColumnStyle, 0.,
|
||||
kColumnLayoutChildrenResultSizes});
|
||||
}
|
||||
|
||||
TEST_CASE (CRowColumnViewTest, RowLayoutMiddleCenterStyleWithSpacing)
|
||||
{
|
||||
testWithLayoutStyle ({CRowColumnView::kMiddleCenter, CRowColumnView::kRowStyle, 4.,
|
||||
kRowLayoutChildrenResultSizesWithSpacing});
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,378 @@
|
||||
// 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 "../../../uidescription/icontroller.h"
|
||||
#include "../unittests.h"
|
||||
#include "eventhelpers.h"
|
||||
#include <array>
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
namespace {
|
||||
|
||||
class SplitViewController : public IController, public ISplitViewController
|
||||
{
|
||||
public:
|
||||
void valueChanged (CControl* pControl) override {}
|
||||
bool getSplitViewSizeConstraint (int32_t index, CCoord& minSize, CCoord& maxSize,
|
||||
CSplitView* splitView) override
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
minSize = 10;
|
||||
maxSize = 50;
|
||||
}
|
||||
else
|
||||
{
|
||||
minSize = 10;
|
||||
maxSize = 100;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ISplitViewSeparatorDrawer* getSplitViewSeparatorDrawer (CSplitView* splitView) override
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool storeViewSize (int32_t index, const CCoord& size, CSplitView* splitView) override
|
||||
{
|
||||
sizes[static_cast<size_t> (index)] = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool restoreViewSize (int32_t index, CCoord& size, CSplitView* splitView) override
|
||||
{
|
||||
if (index == 0)
|
||||
size = 20;
|
||||
else if (index == 1)
|
||||
size = 70;
|
||||
return true;
|
||||
}
|
||||
std::array<CCoord, 2> sizes;
|
||||
};
|
||||
|
||||
class SeparatorSubView : public CView
|
||||
{
|
||||
public:
|
||||
SeparatorSubView () : CView (CRect (0, 0, 0, 0)) {}
|
||||
|
||||
bool mouseDownCalled {false};
|
||||
bool mouseMovedCalled {false};
|
||||
bool mouseUpCalled {false};
|
||||
bool mouseCancelCalled {false};
|
||||
|
||||
CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
mouseDownCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
mouseMovedCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
mouseUpCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseCancel () override
|
||||
{
|
||||
mouseCancelCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous
|
||||
|
||||
TEST_CASE (CSplitViewTest, AddViewsHorizontal)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kHorizontal);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 50, 100));
|
||||
auto view2 = new CView (CRect (0, 0, 40, 100));
|
||||
sv->addView (view1);
|
||||
EXPECT (sv->getNbViews () == 1);
|
||||
sv->addView (view2);
|
||||
EXPECT (sv->getNbViews () == 3);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 50, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (60, 0, 100, 100));
|
||||
sv->removeView (view1);
|
||||
EXPECT (sv->getNbViews () == 1);
|
||||
EXPECT (view2->getViewSize () == CRect (60, 0, 100, 100));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, AddViewsVertical)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kVertical);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 100, 50));
|
||||
auto view2 = new CView (CRect (0, 0, 100, 40));
|
||||
sv->addView (view1);
|
||||
EXPECT (sv->getNbViews () == 1);
|
||||
sv->addView (view2);
|
||||
EXPECT (sv->getNbViews () == 3);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 50));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 60, 100, 100));
|
||||
sv->removeView (view2);
|
||||
EXPECT (sv->getNbViews () == 1);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 50));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ResizeAllViewsHorizontal)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kHorizontal);
|
||||
sv->setResizeMethod (CSplitView::kResizeAllViews);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 50, 100));
|
||||
auto view2 = new CView (CRect (0, 0, 40, 100));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->setViewSize (CRect (0, 0, 120, 100));
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 60, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (70, 0, 120, 100));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ResizeAllViewsVertical)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kVertical);
|
||||
sv->setResizeMethod (CSplitView::kResizeAllViews);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 100, 50));
|
||||
auto view2 = new CView (CRect (0, 0, 100, 40));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->setViewSize (CRect (0, 0, 100, 120));
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 60));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 70, 100, 120));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ResizeFirstViewHorizontal)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kHorizontal);
|
||||
sv->setResizeMethod (CSplitView::kResizeFirstView);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 50, 100));
|
||||
auto view2 = new CView (CRect (0, 0, 40, 100));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->setViewSize (CRect (0, 0, 120, 100));
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 70, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (80, 0, 120, 100));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ResizeFirstViewVertical)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kVertical);
|
||||
sv->setResizeMethod (CSplitView::kResizeFirstView);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 100, 50));
|
||||
auto view2 = new CView (CRect (0, 0, 100, 40));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->setViewSize (CRect (0, 0, 100, 120));
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 70));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 80, 100, 120));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ResizeLastViewHorizontal)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kHorizontal);
|
||||
sv->setResizeMethod (CSplitView::kResizeLastView);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 50, 100));
|
||||
auto view2 = new CView (CRect (0, 0, 40, 100));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->setViewSize (CRect (0, 0, 120, 100));
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 50, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (60, 0, 120, 100));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, resizeLastViewVertical)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kVertical);
|
||||
sv->setResizeMethod (CSplitView::kResizeLastView);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 100, 50));
|
||||
auto view2 = new CView (CRect (0, 0, 100, 40));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->setViewSize (CRect (0, 0, 100, 120));
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 50));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 60, 100, 120));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ResizeSecondViewHorizontal)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kHorizontal);
|
||||
sv->setResizeMethod (CSplitView::kResizeSecondView);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 50, 100));
|
||||
auto view2 = new CView (CRect (0, 0, 20, 100));
|
||||
auto view3 = new CView (CRect (0, 0, 10, 100));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->addView (view3);
|
||||
sv->setViewSize (CRect (0, 0, 120, 100));
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 50, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (60, 0, 100, 100));
|
||||
EXPECT (view3->getViewSize () == CRect (110, 0, 120, 100));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ResizeSecondViewVertical)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kVertical);
|
||||
sv->setResizeMethod (CSplitView::kResizeSecondView);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 100, 50));
|
||||
auto view2 = new CView (CRect (0, 0, 100, 20));
|
||||
auto view3 = new CView (CRect (0, 0, 100, 10));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->addView (view3);
|
||||
sv->setViewSize (CRect (0, 0, 100, 120));
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 50));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 60, 100, 100));
|
||||
EXPECT (view3->getViewSize () == CRect (0, 110, 100, 120));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, SetSeparatorWidth)
|
||||
{
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kHorizontal);
|
||||
sv->setResizeMethod (CSplitView::kResizeFirstView);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 40, 100));
|
||||
auto view2 = new CView (CRect (0, 0, 20, 100));
|
||||
auto view3 = new CView (CRect (0, 0, 20, 100));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->addView (view3);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 40, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (50, 0, 70, 100));
|
||||
EXPECT (view3->getViewSize () == CRect (80, 0, 100, 100));
|
||||
sv->setSeparatorWidth (20);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 40, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (60, 0, 70, 100));
|
||||
EXPECT (view3->getViewSize () == CRect (90, 0, 100, 100));
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ControllerHorizontal)
|
||||
{
|
||||
auto controller = new SplitViewController ();
|
||||
auto container = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setAttribute (kCViewControllerAttribute, controller);
|
||||
sv->setStyle (CSplitView::kHorizontal);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 40, 100));
|
||||
auto view2 = new CView (CRect (0, 0, 50, 100));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->attached (container);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 20, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (30, 0, 100, 100));
|
||||
|
||||
dispatchMouseEvent<MouseDownEvent> (sv, {25., 1.}, MouseButton::Left);
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {55., 1.}, MouseButton::Left);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 50, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (60, 0, 100, 100));
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {65., 1.}, MouseButton::Left);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 50, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (60, 0, 100, 100));
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {15., 1.}, MouseButton::Left);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 10, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (20, 0, 100, 100));
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {1., 1.}, MouseButton::Left);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 10, 100));
|
||||
EXPECT (view2->getViewSize () == CRect (20, 0, 100, 100));
|
||||
dispatchMouseEvent<MouseUpEvent> (sv, {1., 1.}, MouseButton::Left);
|
||||
|
||||
sv->removed (container);
|
||||
EXPECT (controller->sizes[0] == 10);
|
||||
EXPECT (controller->sizes[1] == 80);
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, ControllerVertical)
|
||||
{
|
||||
auto controller = new SplitViewController ();
|
||||
auto container = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setAttribute (kCViewControllerAttribute, controller);
|
||||
sv->setStyle (CSplitView::kVertical);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 100, 40));
|
||||
auto view2 = new CView (CRect (0, 0, 100, 50));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
sv->attached (container);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 20));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 30, 100, 100));
|
||||
dispatchMouseEvent<MouseDownEvent> (sv, {1., 25.}, MouseButton::Left);
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {1., 55.}, MouseButton::Left);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 50));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 60, 100, 100));
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {1., 65.}, MouseButton::Left);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 50));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 60, 100, 100));
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {1., 15.}, MouseButton::Left);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 10));
|
||||
EXPECT (view2->getViewSize () == CRect (00, 20, 100, 100));
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {1., 1.}, MouseButton::Left);
|
||||
EXPECT (view1->getViewSize () == CRect (0, 0, 100, 10));
|
||||
EXPECT (view2->getViewSize () == CRect (0, 20, 100, 100));
|
||||
dispatchMouseEvent<MouseUpEvent> (sv, {1., 1.}, MouseButton::Left);
|
||||
|
||||
sv->removed (container);
|
||||
EXPECT (controller->sizes[0] == 10);
|
||||
EXPECT (controller->sizes[1] == 80);
|
||||
}
|
||||
|
||||
TEST_CASE (CSplitViewTest, SeparatorSubView)
|
||||
{
|
||||
auto container = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
auto sv = owned (new CSplitView (CRect (0, 0, 100, 100)));
|
||||
sv->setStyle (CSplitView::kHorizontal);
|
||||
sv->setResizeMethod (CSplitView::kResizeFirstView);
|
||||
sv->setSeparatorWidth (10);
|
||||
auto view1 = new CView (CRect (0, 0, 40, 100));
|
||||
auto view2 = new CView (CRect (0, 0, 20, 100));
|
||||
sv->addView (view1);
|
||||
sv->addView (view2);
|
||||
auto sepView = new SeparatorSubView ();
|
||||
sepView->setViewSize (CRect (0, 0, 10, 10));
|
||||
sepView->setMouseableArea (CRect (0, 0, 10, 10));
|
||||
sv->addViewToSeparator (0, sepView);
|
||||
sv->attached (container);
|
||||
dispatchMouseEvent<MouseDownEvent> (sv, {41., 25.}, MouseButton::Left);
|
||||
EXPECT (sepView->mouseDownCalled == false);
|
||||
dispatchMouseEvent<MouseDownEvent> (sv, {41., 1.}, MouseButton::Left);
|
||||
EXPECT (sepView->mouseDownCalled);
|
||||
dispatchMouseEvent<MouseMoveEvent> (sv, {41., 3.}, MouseButton::Left);
|
||||
EXPECT (sepView->mouseMovedCalled);
|
||||
dispatchMouseEvent<MouseUpEvent> (sv, {41., 3.}, MouseButton::Left);
|
||||
EXPECT (sepView->mouseUpCalled);
|
||||
dispatchMouseEvent<MouseDownEvent> (sv, {41., 1.}, MouseButton::Left);
|
||||
dispatchMouseCancelEvent (sv);
|
||||
EXPECT (sepView->mouseCancelCalled);
|
||||
sv->removed (container);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,617 @@
|
||||
// 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/cgraphicspath.h"
|
||||
#include "../../../lib/coffscreencontext.h"
|
||||
#include "../../../lib/cview.h"
|
||||
#include "../../../lib/cviewcontainer.h"
|
||||
#include "../../../lib/dragging.h"
|
||||
#include "../../../lib/events.h"
|
||||
#include "../../../lib/idatapackage.h"
|
||||
#include "../../../lib/iviewlistener.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
#if MAC
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace VSTGUI {
|
||||
namespace {
|
||||
class View : public CView
|
||||
{
|
||||
public:
|
||||
View () : CView (CRect (0, 0, 10, 10)) {}
|
||||
void onIdle () override { onIdleCalled = true; }
|
||||
|
||||
bool onIdleCalled {false};
|
||||
};
|
||||
|
||||
struct ViewListener : public IViewListener
|
||||
{
|
||||
void viewSizeChanged (CView* view, const CRect& oldSize) override { sizeChangedCalled = true; }
|
||||
void viewAttached (CView* view) override { attachedCalled = true; }
|
||||
void viewRemoved (CView* view) override { removedCalled = true; }
|
||||
void viewLostFocus (CView* view) override { lostFocusCalled = true; }
|
||||
void viewTookFocus (CView* view) override { tookFocusCalled = true; }
|
||||
void viewWillDelete (CView* view) override
|
||||
{
|
||||
view->unregisterViewListener (this);
|
||||
willDeleteCalled = true;
|
||||
}
|
||||
void viewOnMouseEnabled (CView* view, bool state) override {}
|
||||
|
||||
bool sizeChangedCalled {false};
|
||||
bool attachedCalled {false};
|
||||
bool removedCalled {false};
|
||||
bool lostFocusCalled {false};
|
||||
bool tookFocusCalled {false};
|
||||
bool willDeleteCalled {false};
|
||||
};
|
||||
|
||||
} // anonymous
|
||||
|
||||
TEST_CASE (CViewTest, VisibleState)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
EXPECT (v->isVisible () == true);
|
||||
v->setVisible (false);
|
||||
EXPECT (v->isVisible () == false);
|
||||
v->setVisible (true);
|
||||
EXPECT (v->isVisible () == true);
|
||||
v->setAlphaValue (0.f);
|
||||
EXPECT (v->isVisible () == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, TransparencyState)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
EXPECT (v->getTransparency () == false);
|
||||
v->setTransparency (true);
|
||||
EXPECT (v->getTransparency () == true);
|
||||
v->setTransparency (false);
|
||||
EXPECT (v->getTransparency () == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, FocusState)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
EXPECT (v->wantsFocus () == false);
|
||||
v->setWantsFocus (true);
|
||||
EXPECT (v->wantsFocus () == true);
|
||||
v->setWantsFocus (false);
|
||||
EXPECT (v->wantsFocus () == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, IdleState)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
EXPECT (v->wantsIdle () == false);
|
||||
v->setWantsIdle (true);
|
||||
EXPECT (v->wantsIdle () == true);
|
||||
v->setWantsIdle (false);
|
||||
EXPECT (v->wantsIdle () == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, MouseEnabledState)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
EXPECT (v->getMouseEnabled () == true);
|
||||
v->setMouseEnabled (false);
|
||||
EXPECT (v->getMouseEnabled () == false);
|
||||
v->setMouseEnabled (true);
|
||||
EXPECT (v->getMouseEnabled () == true);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, AutosizeFlags)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
EXPECT (v->getAutosizeFlags () == kAutosizeNone);
|
||||
v->setAutosizeFlags (kAutosizeLeft);
|
||||
EXPECT (v->getAutosizeFlags () == kAutosizeLeft);
|
||||
v->setAutosizeFlags (kAutosizeLeft | kAutosizeTop);
|
||||
EXPECT (v->getAutosizeFlags () == (kAutosizeLeft | kAutosizeTop));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, Attributes)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
uint32_t outSize;
|
||||
void* outData = nullptr;
|
||||
EXPECT (v->getAttribute (0, 10, outData, outSize) == false);
|
||||
EXPECT (v->removeAttribute (0) == false);
|
||||
uint64_t myAttr = 500;
|
||||
EXPECT (v->setAttribute (0, 0, &myAttr) == false);
|
||||
EXPECT (v->setAttribute (0, sizeof (myAttr), nullptr) == false);
|
||||
EXPECT (v->setAttribute ('myAt', sizeof (myAttr), &myAttr) == true);
|
||||
myAttr = 10;
|
||||
EXPECT (v->getAttributeSize ('myAt', outSize) == true);
|
||||
EXPECT (outSize == sizeof (myAttr));
|
||||
EXPECT (v->getAttribute ('myAt', sizeof (myAttr), &myAttr, outSize) == true);
|
||||
EXPECT (myAttr == 500);
|
||||
myAttr = 100;
|
||||
EXPECT (v->setAttribute ('myAt', sizeof (myAttr), &myAttr) == true);
|
||||
myAttr = 102;
|
||||
EXPECT (v->getAttribute ('myAt', sizeof (myAttr), &myAttr, outSize) == true);
|
||||
EXPECT (myAttr == 100);
|
||||
EXPECT (v->removeAttribute ('myAt') == true);
|
||||
EXPECT (v->getAttribute ('myAt', sizeof (myAttr), &myAttr, outSize) == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ResizeAttribute)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
uint32_t outSize;
|
||||
uint8_t firstData = 8;
|
||||
EXPECT (v->setAttribute (0, sizeof (firstData), &firstData));
|
||||
firstData = 0;
|
||||
EXPECT (v->getAttribute (0, sizeof (firstData), &firstData, outSize));
|
||||
EXPECT (firstData == 8);
|
||||
uint32_t secondData = 32;
|
||||
EXPECT (v->setAttribute (0, sizeof (secondData), &secondData));
|
||||
secondData = 0;
|
||||
EXPECT (v->getAttribute (0, sizeof (firstData), &firstData, outSize) == false);
|
||||
EXPECT (v->getAttribute (0, sizeof (secondData), &secondData, outSize));
|
||||
EXPECT (secondData == 32);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewListener)
|
||||
{
|
||||
ViewListener listener;
|
||||
{
|
||||
auto v = new View ();
|
||||
v->registerViewListener (&listener);
|
||||
v->setViewSize (CRect (1, 2, 3, 4));
|
||||
auto container1 = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
auto container2 = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
container2->addView (v);
|
||||
container2->attached (container1);
|
||||
v->takeFocus ();
|
||||
v->looseFocus ();
|
||||
container2->removeView (v);
|
||||
container2->removed (container1);
|
||||
}
|
||||
EXPECT (listener.sizeChangedCalled);
|
||||
EXPECT (listener.attachedCalled);
|
||||
EXPECT (listener.removedCalled);
|
||||
EXPECT (listener.tookFocusCalled);
|
||||
EXPECT (listener.lostFocusCalled);
|
||||
EXPECT (listener.willDeleteCalled);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, CoordCalculations)
|
||||
{
|
||||
auto parent = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
auto container = owned (new CViewContainer (CRect (50, 50, 100, 100)));
|
||||
container->attached (parent);
|
||||
auto v = new View ();
|
||||
container->addView (v);
|
||||
CPoint p (0, 0);
|
||||
v->localToFrame (p);
|
||||
EXPECT (p.x == 50 && p.y == 50);
|
||||
p (52, 53);
|
||||
v->frameToLocal (p);
|
||||
EXPECT (p.x == 2 && p.y == 3);
|
||||
container->removed (parent);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, VisibleViewSize)
|
||||
{
|
||||
auto parent = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
auto container = owned (new CViewContainer (CRect (50, 50, 100, 100)));
|
||||
container->attached (parent);
|
||||
auto v = new View ();
|
||||
v->setViewSize (CRect (20, 20, 150, 150));
|
||||
container->addView (v);
|
||||
auto visible = v->getVisibleViewSize ();
|
||||
EXPECT (visible == CRect (20, 20, 50, 50));
|
||||
container->removeView (v);
|
||||
container->removed (parent);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, GlobalTransform)
|
||||
{
|
||||
auto container1 = owned (new CViewContainer (CRect (0, 0, 10, 10)));
|
||||
auto container2 = new CViewContainer (CRect (0, 0, 10, 10));
|
||||
container1->setTransform (CGraphicsTransform ().translate (10, 20));
|
||||
container2->setTransform (CGraphicsTransform ().translate (15, 35));
|
||||
container1->addView (container2);
|
||||
auto v = new View ();
|
||||
container2->addView (v);
|
||||
container2->attached (container1);
|
||||
auto transform = v->getGlobalTransform ();
|
||||
EXPECT (transform.dx == 25 && transform.dy == 55);
|
||||
|
||||
CPoint p (0, 0);
|
||||
v->translateToGlobal (p);
|
||||
EXPECT (p.x == 25 && p.y == 55);
|
||||
v->translateToLocal (p);
|
||||
EXPECT (p.x == 0 && p.y == 0);
|
||||
|
||||
auto p2 = v->translateToGlobal (CRect (0, 0, 1, 1));
|
||||
EXPECT (p2 == CRect (25, 55, 26, 56));
|
||||
p2 = v->translateToLocal (CRect (25, 55, 26, 56));
|
||||
EXPECT (p2 == CRect (0, 0, 1, 1));
|
||||
|
||||
container2->removed (container1);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, HitTest)
|
||||
{
|
||||
auto v = owned (new View ());
|
||||
v->setMouseableArea (CRect (20, 20, 40, 40));
|
||||
EXPECT (v->hitTest (CPoint (5, 5)) == false);
|
||||
EXPECT (v->hitTest (CPoint (20, 20)) == true);
|
||||
EXPECT (v->hitTest (CPoint (40, 40)) == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, DefaultHandling)
|
||||
{
|
||||
auto v = makeOwned<View> ();
|
||||
KeyboardEvent keyEvent;
|
||||
v->dispatchEvent (keyEvent);
|
||||
EXPECT (keyEvent.consumed == false);
|
||||
keyEvent.type = EventType::KeyUp;
|
||||
v->dispatchEvent (keyEvent);
|
||||
EXPECT (keyEvent.consumed == false);
|
||||
MouseWheelEvent event;
|
||||
v->onMouseWheelEvent (event);
|
||||
EXPECT (event.consumed == false);
|
||||
CPoint p (0, 0);
|
||||
EXPECT (v->onMouseDown (p, kLButton) == kMouseEventNotImplemented);
|
||||
EXPECT (v->onMouseUp (p, kLButton) == kMouseEventNotImplemented);
|
||||
EXPECT (v->onMouseMoved (p, kLButton) == kMouseEventNotImplemented);
|
||||
EXPECT (v->onMouseCancel () == kMouseEventNotImplemented);
|
||||
EXPECT (v->onMouseEntered (p, kLButton) == kMouseEventNotImplemented);
|
||||
EXPECT (v->onMouseExited (p, kLButton) == kMouseEventNotImplemented);
|
||||
EXPECT (v->notify (nullptr, nullptr) == kMessageUnknown);
|
||||
|
||||
EXPECT (v->doDrag (DragDescription (nullptr)) == false);
|
||||
|
||||
EXPECT (v->getDropTarget () == nullptr);
|
||||
EXPECT (v->getEditor () == nullptr);
|
||||
EXPECT (v->isDirty () == false);
|
||||
EXPECT (v->sizeToFit () == false);
|
||||
EXPECT (v->getBackground () == nullptr);
|
||||
EXPECT (v->getDisabledBackground () == nullptr);
|
||||
EXPECT (v->getDrawBackground () == nullptr);
|
||||
EXPECT (v->checkUpdate (CRect (0, 0, 5, 5)) == true);
|
||||
EXPECT (v->getWidth () == 10);
|
||||
EXPECT (v->getHeight () == 10);
|
||||
EXPECT (v->getViewSize () == v->getMouseableArea ());
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, PathHitTest)
|
||||
{
|
||||
auto v = makeOwned<View> ();
|
||||
v->setViewSize ({0., 0., 100., 100.});
|
||||
{
|
||||
auto drawContext = COffscreenContext::create ({100., 100.});
|
||||
auto path = owned (drawContext->createGraphicsPath ());
|
||||
path->addRect ({10., 10., 80., 80.});
|
||||
v->setHitTestPath (path);
|
||||
}
|
||||
EXPECT_FALSE (v->hitTest ({5., 5.}, noEvent ()));
|
||||
EXPECT_TRUE (v->hitTest ({15., 15.}, noEvent ()));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class TestView : public CView
|
||||
{
|
||||
public:
|
||||
TestView () : CView (CRect (0, 0, 10, 10))
|
||||
{
|
||||
std::fill (called.begin (), called.end (), false);
|
||||
}
|
||||
|
||||
void onMouseDownEvent (MouseDownEvent& event) override
|
||||
{
|
||||
called[e2p (EventType::MouseDown)] = true;
|
||||
}
|
||||
void onMouseMoveEvent (MouseMoveEvent& event) override
|
||||
{
|
||||
called[e2p (EventType::MouseMove)] = true;
|
||||
}
|
||||
void onMouseUpEvent (MouseUpEvent& event) override { called[e2p (EventType::MouseUp)] = true; }
|
||||
void onMouseCancelEvent (MouseCancelEvent& event) override
|
||||
{
|
||||
called[e2p (EventType::MouseCancel)] = true;
|
||||
}
|
||||
void onMouseEnterEvent (MouseEnterEvent& event) override
|
||||
{
|
||||
called[e2p (EventType::MouseEnter)] = true;
|
||||
}
|
||||
void onMouseExitEvent (MouseExitEvent& event) override
|
||||
{
|
||||
called[e2p (EventType::MouseExit)] = true;
|
||||
}
|
||||
void onMouseWheelEvent (MouseWheelEvent& event) override
|
||||
{
|
||||
called[e2p (EventType::MouseWheel)] = true;
|
||||
}
|
||||
void onZoomGestureEvent (ZoomGestureEvent& event) override
|
||||
{
|
||||
called[e2p (EventType::ZoomGesture)] = true;
|
||||
}
|
||||
void onKeyboardEvent (KeyboardEvent& event) override { called[e2p (EventType::KeyUp)] = true; }
|
||||
|
||||
bool eventCalled (EventType t) const { return called[e2p (t)]; }
|
||||
|
||||
private:
|
||||
static constexpr size_t e2p (EventType t) { return static_cast<size_t> (t); }
|
||||
std::array<bool, static_cast<size_t> (EventType::KeyDown)> called;
|
||||
};
|
||||
|
||||
struct TestViewEventHandler : IViewEventListener
|
||||
{
|
||||
using Func = std::function<void (CView*, Event&)>;
|
||||
TestViewEventHandler (Func&& func) : func (std::move (func)) {}
|
||||
void viewOnEvent (CView* view, Event& event) override { func (view, event); }
|
||||
|
||||
Func func;
|
||||
};
|
||||
|
||||
} // anonymous
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerMouseDownEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
MouseDownEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::MouseDown));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::MouseDown));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerMouseMoveEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
MouseMoveEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::MouseMove));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::MouseMove));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerMouseUpEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
MouseUpEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::MouseUp));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::MouseUp));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerMouseCancelEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
MouseCancelEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::MouseCancel));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::MouseCancel));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerMouseEnterEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
MouseEnterEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::MouseEnter));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::MouseEnter));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerMouseExitEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
MouseExitEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::MouseExit));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::MouseExit));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerMouseWheelEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
MouseWheelEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::MouseWheel));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::MouseWheel));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerZoomGestureEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
ZoomGestureEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::ZoomGesture));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::ZoomGesture));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, ViewEventListenerKeyEvent)
|
||||
{
|
||||
auto v = makeOwned<TestView> ();
|
||||
TestViewEventHandler listener ([] (CView*, Event& event) { event.consumed = true; });
|
||||
v->registerViewEventListener (&listener);
|
||||
KeyboardEvent event;
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_FALSE (v->eventCalled (EventType::KeyUp));
|
||||
v->unregisterViewEventListener (&listener);
|
||||
event.consumed.reset ();
|
||||
v->dispatchEvent (event);
|
||||
EXPECT_TRUE (v->eventCalled (EventType::KeyUp));
|
||||
}
|
||||
|
||||
#if MAC // TODO: Make test work on other platforms too.
|
||||
|
||||
TEST_CASE (CViewTest, IdleAfterAttached)
|
||||
{
|
||||
auto parent = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
auto container = owned (new CViewContainer (CRect (50, 50, 100, 100)));
|
||||
container->attached (parent);
|
||||
auto v = new View ();
|
||||
container->addView (v);
|
||||
v->setWantsIdle (true);
|
||||
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.2, false);
|
||||
EXPECT (v->onIdleCalled == true);
|
||||
v->setWantsIdle (false);
|
||||
v->onIdleCalled = false;
|
||||
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.2, false);
|
||||
EXPECT (v->onIdleCalled == false);
|
||||
container->removeView (v);
|
||||
container->removed (parent);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewTest, IdleBeforeAttached)
|
||||
{
|
||||
auto parent = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
auto container = owned (new CViewContainer (CRect (50, 50, 100, 100)));
|
||||
auto v = new View ();
|
||||
container->addView (v);
|
||||
v->setWantsIdle (true);
|
||||
container->attached (parent);
|
||||
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.2, true);
|
||||
EXPECT (v->onIdleCalled == true);
|
||||
container->removeView (v);
|
||||
container->removed (parent);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
struct DataPackage : IDataPackage
|
||||
{
|
||||
UTF8String str;
|
||||
UTF8String path;
|
||||
int8_t binary[3];
|
||||
|
||||
uint32_t getCount () const override { return 3; }
|
||||
|
||||
uint32_t getDataSize (uint32_t index) const override
|
||||
{
|
||||
if (index == 0)
|
||||
return static_cast<uint32_t> (str.length ());
|
||||
else if (index == 1)
|
||||
return static_cast<uint32_t> (path.length ());
|
||||
else if (index == 2)
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Type getDataType (uint32_t index) const override
|
||||
{
|
||||
if (index == 0)
|
||||
return kText;
|
||||
else if (index == 1)
|
||||
return kFilePath;
|
||||
else if (index == 2)
|
||||
return kBinary;
|
||||
return kError;
|
||||
}
|
||||
|
||||
uint32_t getData (uint32_t index, const void*& buffer, Type& type) const override
|
||||
{
|
||||
type = kError;
|
||||
if (index == 0)
|
||||
{
|
||||
buffer = str.data ();
|
||||
type = kText;
|
||||
}
|
||||
else if (index == 1)
|
||||
{
|
||||
buffer = path.data ();
|
||||
type = kFilePath;
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
buffer = binary;
|
||||
type = kBinary;
|
||||
}
|
||||
return getDataSize (index);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE (CDragContainerHelperTest, Count)
|
||||
{
|
||||
DataPackage package;
|
||||
CDragContainerHelper helper (&package);
|
||||
EXPECT (helper.getCount () == 3);
|
||||
}
|
||||
|
||||
TEST_CASE (CDragContainerHelper, GetType)
|
||||
{
|
||||
DataPackage package;
|
||||
CDragContainerHelper helper (&package);
|
||||
EXPECT (helper.getType (0) == CDragContainerHelper::kUnicodeText);
|
||||
EXPECT (helper.getType (1) == CDragContainerHelper::kFile);
|
||||
EXPECT (helper.getType (2) == CDragContainerHelper::kUnknown);
|
||||
EXPECT (helper.getType (3) == CDragContainerHelper::kError);
|
||||
}
|
||||
|
||||
TEST_CASE (CDragContainerHelper, Iteration)
|
||||
{
|
||||
DataPackage package;
|
||||
package.str = "Test";
|
||||
package.path = "/var/tmp/test";
|
||||
CDragContainerHelper helper (&package);
|
||||
int32_t size;
|
||||
int32_t type;
|
||||
auto res = helper.first (size, type);
|
||||
EXPECT (res == package.str.data ());
|
||||
EXPECT (size == static_cast<int32_t> (package.str.length ()));
|
||||
EXPECT (type == CDragContainerHelper::kUnicodeText);
|
||||
res = helper.next (size, type);
|
||||
EXPECT (res == package.path.data ());
|
||||
EXPECT (size == static_cast<int32_t> (package.path.length ()));
|
||||
EXPECT (type == CDragContainerHelper::kFile);
|
||||
res = helper.next (size, type);
|
||||
EXPECT (res == package.binary);
|
||||
EXPECT (size == 3);
|
||||
EXPECT (type == CDragContainerHelper::kUnknown);
|
||||
res = helper.next (size, type);
|
||||
EXPECT (res == nullptr);
|
||||
EXPECT (size == 0);
|
||||
EXPECT (type == CDragContainerHelper::kError);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+641
@@ -0,0 +1,641 @@
|
||||
// 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/cframe.h"
|
||||
#include "../../../lib/iviewlistener.h"
|
||||
#include "../../../lib/ccolor.h"
|
||||
#include "../../../lib/dragging.h"
|
||||
#include "../../../lib/events.h"
|
||||
#include "../unittests.h"
|
||||
#include "eventhelpers.h"
|
||||
#include <vector>
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
namespace {
|
||||
|
||||
class TestViewContainerListener : public IViewContainerListener
|
||||
{
|
||||
public:
|
||||
void viewContainerViewAdded (CViewContainer* container, CView* view) override
|
||||
{ viewAddedCalled = true; }
|
||||
void viewContainerViewRemoved (CViewContainer* container, CView* view) override
|
||||
{ viewRemovedCalled = true; }
|
||||
void viewContainerViewZOrderChanged (CViewContainer* container, CView* view) override
|
||||
{ viewZOrderChangedCalled = true; }
|
||||
void viewContainerTransformChanged (CViewContainer* container) override
|
||||
{ transformChangedCalled = true; }
|
||||
|
||||
bool viewAddedCalled {false};
|
||||
bool viewRemovedCalled {false};
|
||||
bool viewZOrderChangedCalled {false};
|
||||
bool transformChangedCalled {false};
|
||||
};
|
||||
|
||||
class TestView1 : public CView
|
||||
{
|
||||
public:
|
||||
TestView1 () : CView (CRect (0, 0, 10, 10)) {}
|
||||
};
|
||||
|
||||
class TestView2 : public CView
|
||||
{
|
||||
public:
|
||||
TestView2 () : CView (CRect (10, 10, 20, 20)) {}
|
||||
};
|
||||
|
||||
class MouseEventCheckView : public CView, public DropTargetAdapter
|
||||
{
|
||||
public:
|
||||
MouseEventCheckView () : CView (CRect ()) {}
|
||||
|
||||
bool mouseDownCalled {false};
|
||||
bool mouseMovedCalled {false};
|
||||
bool mouseUpCalled {false};
|
||||
bool mouseCancelCalled {false};
|
||||
bool onDragEnterCalled {false};
|
||||
bool onDragLeaveCalled {false};
|
||||
bool onDragMoveCalled {false};
|
||||
bool onWheelCalled {false};
|
||||
|
||||
CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
mouseDownCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
mouseMovedCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
mouseUpCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseCancel () override
|
||||
{
|
||||
mouseCancelCalled = true;
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
SharedPointer<IDropTarget> getDropTarget () override { return this; }
|
||||
DragOperation onDragEnter (DragEventData data) override
|
||||
{
|
||||
onDragEnterCalled = true;
|
||||
return DragOperation::None;
|
||||
}
|
||||
|
||||
void onDragLeave (DragEventData data) override
|
||||
{
|
||||
onDragLeaveCalled = true;
|
||||
}
|
||||
|
||||
DragOperation onDragMove (DragEventData data) override
|
||||
{
|
||||
onDragMoveCalled = true;
|
||||
return DragOperation::None;
|
||||
}
|
||||
|
||||
void onMouseWheelEvent (MouseWheelEvent& event) override
|
||||
{
|
||||
onWheelCalled = true;
|
||||
event.consumed = true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // anonymous
|
||||
|
||||
TEST_SUITE_SETUP (CViewContainerTest)
|
||||
{
|
||||
SharedPointer<CViewContainer> container = makeOwned<CViewContainer> (CRect (0, 0, 200, 200));
|
||||
TEST_SUITE_SET_STORAGE (SharedPointer<CViewContainer>, container);
|
||||
}
|
||||
|
||||
TEST_SUITE_TEARDOWN (CViewContainerTest)
|
||||
{
|
||||
TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>) = nullptr;
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, ChangeViewZOrder)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
CView* view1 = new CView (CRect (0, 0, 10, 10));
|
||||
CView* view2 = new CView (CRect (0, 0, 10, 10));
|
||||
CView* view3 = new CView (CRect (0, 0, 10, 10));
|
||||
container->addView (view1);
|
||||
container->addView (view2);
|
||||
container->addView (view3);
|
||||
EXPECT(container->changeViewZOrder (view3, 0));
|
||||
EXPECT(container->getView (0) == view3);
|
||||
EXPECT(container->getView (1) == view1);
|
||||
EXPECT(container->getView (2) == view2);
|
||||
EXPECT(container->getView (3) == nullptr);
|
||||
EXPECT(container->changeViewZOrder (view3, 4) == false);
|
||||
EXPECT(container->changeViewZOrder (view3, 0));
|
||||
EXPECT(container->changeViewZOrder (view3, 1));
|
||||
EXPECT(container->getView (0) == view1);
|
||||
EXPECT(container->getView (1) == view3);
|
||||
EXPECT(container->getView (2) == view2);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, AddView)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CView* view = new CView (CRect (0, 0, 10, 10));
|
||||
CView* view2 = new CView (CRect (0, 0, 10, 10));
|
||||
|
||||
EXPECT(container->addView (view));
|
||||
EXPECT(container->addView (view2));
|
||||
|
||||
EXPECT(container->isChild (view));
|
||||
EXPECT(container->isChild (view2));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, AddView2)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto v = new TestView1 ();
|
||||
CRect r (30, 40, 50, 60);
|
||||
EXPECT(container->addView (v, r, false));
|
||||
EXPECT(v->getMouseEnabled () == false);
|
||||
EXPECT(v->getMouseableArea () == r);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, AddViewTwice)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CView* view = new CView (CRect (0, 0, 10, 10));
|
||||
EXPECT (container->addView (view));
|
||||
EXPECT_EXCEPTION (container->addView (view), "view is already added to a container view");
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, AddViewToTwoContainer)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CView* view = new CView (CRect (0, 0, 10, 10));
|
||||
EXPECT (container->addView (view));
|
||||
auto c2 = owned (new CViewContainer (CRect ()));
|
||||
EXPECT_EXCEPTION (c2->addView (view), "view is already added to a container view");
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, AddViewBeforeOtherView)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CView* view = new CView (CRect (0, 0, 10, 10));
|
||||
CView* view2 = new CView (CRect (0, 0, 10, 10));
|
||||
|
||||
EXPECT (container->addView (view));
|
||||
EXPECT (container->addView (view2, view));
|
||||
|
||||
EXPECT (container->getView (0) == view2)
|
||||
EXPECT (container->getView (1) == view)
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, RemoveView)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto view = makeOwned<CView> (CRect (0, 0, 10, 10));
|
||||
CView* view2 = new CView (CRect (0, 0, 10, 10));
|
||||
|
||||
container->addView (view);
|
||||
container->addView (view2);
|
||||
container->removeView (view, false);
|
||||
|
||||
EXPECT (container->isChild (view) == false)
|
||||
EXPECT (container->isChild (view2))
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, RemoveAllViews)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto view = makeOwned<CView> (CRect (0, 0, 10, 10));
|
||||
auto view2 = makeOwned<CView> (CRect (0, 0, 10, 10));
|
||||
|
||||
container->addView (view);
|
||||
container->addView (view2);
|
||||
container->removeAll (false);
|
||||
|
||||
EXPECT (container->isChild (view) == false)
|
||||
EXPECT (container->isChild (view2) == false)
|
||||
EXPECT (container->hasChildren () == false)
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, AdvanceNextFocusView)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CFrame* frame = new CFrame (CRect (0, 0, 10, 10), nullptr);
|
||||
frame->onActivate (true);
|
||||
CView* view1 = new CView (CRect (0, 0, 10, 10));
|
||||
CView* view2 = new CView (CRect (0, 0, 10, 10));
|
||||
CView* view3 = new CView (CRect (0, 0, 10, 10));
|
||||
view1->setWantsFocus (true);
|
||||
view2->setWantsFocus (true);
|
||||
view3->setWantsFocus (true);
|
||||
|
||||
container->addView (view1);
|
||||
container->addView (view2);
|
||||
container->addView (view3);
|
||||
frame->addView (container);
|
||||
container->remember ();
|
||||
frame->attached (frame);
|
||||
|
||||
EXPECT (container->advanceNextFocusView (nullptr, true) == true)
|
||||
EXPECT (frame->getFocusView () == view3)
|
||||
EXPECT (container->advanceNextFocusView (view3) == false)
|
||||
frame->setFocusView (nullptr);
|
||||
EXPECT (container->advanceNextFocusView (nullptr) == true)
|
||||
EXPECT (frame->getFocusView () == view1)
|
||||
frame->close ();
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, AutoSizeAll)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CView* view = new CView (container->getViewSize ());
|
||||
view->setAutosizeFlags (kAutosizeAll);
|
||||
container->addView (view);
|
||||
container->setAutosizingEnabled (true);
|
||||
EXPECT (container->getAutosizingEnabled ());
|
||||
container->setViewSize (CRect (0, 0, 500, 500));
|
||||
EXPECT (view->getViewSize ().left == 0)
|
||||
EXPECT (view->getViewSize ().top == 0)
|
||||
EXPECT (view->getViewSize ().right == 500)
|
||||
EXPECT (view->getViewSize ().bottom == 500)
|
||||
container->setAutosizingEnabled (false);
|
||||
EXPECT (container->getAutosizingEnabled () == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, SizeToFit)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CRect r (10, 10, 20, 20);
|
||||
CView* view = new CView (r);
|
||||
container->addView (view);
|
||||
container->sizeToFit ();
|
||||
EXPECT (container->getViewSize ().right == 30)
|
||||
EXPECT (container->getViewSize ().bottom == 30)
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, GetViewAt)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CRect r (10, 10, 20, 20);
|
||||
CView* view = new CView (r);
|
||||
container->addView (view);
|
||||
EXPECT (view == container->getViewAt (r.getTopLeft ()));
|
||||
EXPECT (nullptr == container->getViewAt (CPoint (0, 0)));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, GetViewAtDeep)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CRect r (10, 10, 20, 20);
|
||||
CViewContainer* container2 = new CViewContainer (r);
|
||||
container->addView (container2);
|
||||
CRect r2 (2, 2, 4, 4);
|
||||
CView* view = new CView (r2);
|
||||
container2->addView (view);
|
||||
EXPECT (container->getViewAt (CPoint (12, 12)) == nullptr);
|
||||
EXPECT (container->getViewAt (CPoint (12, 12), GetViewOptions (GetViewOptions::kDeep)) == view);
|
||||
EXPECT (container->getViewAt (CPoint (11, 11), GetViewOptions (GetViewOptions::kDeep)) ==
|
||||
nullptr);
|
||||
EXPECT (container->getViewAt (
|
||||
CPoint (11, 11),
|
||||
GetViewOptions (GetViewOptions::kDeep | GetViewOptions::kIncludeViewContainer)) ==
|
||||
container2);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, Listener)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
TestViewContainerListener listener;
|
||||
container->registerViewContainerListener (&listener);
|
||||
auto view = new CView (CRect (0, 0, 0, 0));
|
||||
container->addView (view);
|
||||
EXPECT (listener.viewAddedCalled == true);
|
||||
container->removeView (view, false);
|
||||
EXPECT (listener.viewRemovedCalled == true);
|
||||
auto view2 = new CView (CRect (0, 0, 0, 0));
|
||||
container->addView (view);
|
||||
container->addView (view2);
|
||||
container->changeViewZOrder (view2, 0);
|
||||
EXPECT (listener.viewZOrderChangedCalled == true);
|
||||
container->setTransform (CGraphicsTransform ().translate (1., 1.));
|
||||
EXPECT (listener.transformChangedCalled == true);
|
||||
container->unregisterViewContainerListener (&listener);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, BackgroundColor)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
container->setBackgroundColor (kGreenCColor);
|
||||
EXPECT (container->getBackgroundColor () == kGreenCColor);
|
||||
container->setBackgroundColorDrawStyle (kDrawFilledAndStroked);
|
||||
EXPECT (container->getBackgroundColorDrawStyle () == kDrawFilledAndStroked);
|
||||
container->setBackgroundColorDrawStyle (kDrawFilled);
|
||||
EXPECT (container->getBackgroundColorDrawStyle () == kDrawFilled);
|
||||
container->setBackgroundColorDrawStyle (kDrawStroked);
|
||||
EXPECT (container->getBackgroundColorDrawStyle () == kDrawStroked);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, BackgroundOffset)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
container->setBackgroundOffset (CPoint (10, 10));
|
||||
EXPECT (container->getBackgroundOffset () == CPoint (10, 10));
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, GetChildViewsOfType)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
container->addView (new TestView1 ());
|
||||
container->addView (new TestView2 ());
|
||||
std::vector<TestView1*> r;
|
||||
container->getChildViewsOfType<TestView1> (r);
|
||||
EXPECT (r.size () == 1);
|
||||
EXPECT (r[0] == container->getView (0));
|
||||
std::vector<TestView2*> r2;
|
||||
container->getChildViewsOfType<TestView2> (r2);
|
||||
EXPECT (r2.size () == 1);
|
||||
EXPECT (r2[0] == container->getView (1));
|
||||
auto c2 = owned (new CViewContainer (CRect (0, 0, 100, 100)));
|
||||
c2->addView (container);
|
||||
r.clear ();
|
||||
c2->getChildViewsOfType<TestView1> (r);
|
||||
EXPECT (r.size () == 0);
|
||||
c2->getChildViewsOfType<TestView1> (r, true);
|
||||
EXPECT (r.size () == 1);
|
||||
c2->removeView (container, false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, Iterator)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto v1 = new TestView1 ();
|
||||
auto v2 = new TestView2 ();
|
||||
container->addView (v1);
|
||||
container->addView (v2);
|
||||
ViewIterator it (container);
|
||||
EXPECT (*it == v1);
|
||||
++it;
|
||||
EXPECT (*it == v2);
|
||||
--it;
|
||||
EXPECT (*it == v1);
|
||||
auto it2 = it++;
|
||||
EXPECT (*it2 == v1);
|
||||
EXPECT (*it == v2);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, ReverseIterator)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto v1 = new TestView1 ();
|
||||
auto v2 = new TestView2 ();
|
||||
container->addView (v1);
|
||||
container->addView (v2);
|
||||
ReverseViewIterator it (container);
|
||||
EXPECT (*it == v2);
|
||||
++it;
|
||||
EXPECT (*it == v1);
|
||||
--it;
|
||||
EXPECT (*it == v2);
|
||||
auto it2 = it++;
|
||||
EXPECT (*it2 == v2);
|
||||
EXPECT (*it == v1);
|
||||
++it;
|
||||
EXPECT (*it == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, MouseEventsInEmptyContainer)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (container, {}), EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (container, {}), EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (container, {}), EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (dispatchMouseCancelEvent (container), EventConsumeState::NotHandled);
|
||||
EXPECT_EQ (dispatchMouseWheelEvent (container, {}, 1., 0.), EventConsumeState::NotHandled);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, MouseEvents)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto v1 = new MouseEventCheckView ();
|
||||
auto v2 = new MouseEventCheckView ();
|
||||
CRect r1 (0, 0, 50, 50);
|
||||
CRect r2 (50, 0, 100, 50);
|
||||
v1->setViewSize (r1);
|
||||
v1->setMouseableArea (r1);
|
||||
v2->setViewSize (r2);
|
||||
v2->setMouseableArea (r2);
|
||||
container->addView (v1);
|
||||
container->addView (v2);
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (container, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (v1->mouseDownCalled);
|
||||
EXPECT_FALSE (v2->mouseDownCalled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (container, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (v1->mouseMovedCalled);
|
||||
EXPECT_FALSE (v2->mouseMovedCalled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (container, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (v1->mouseUpCalled);
|
||||
EXPECT_FALSE (v2->mouseUpCalled);
|
||||
|
||||
EXPECT_EQ (dispatchMouseWheelEvent (container, {60., 10.}, 0.5, 0.),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_FALSE (v1->onWheelCalled);
|
||||
EXPECT_TRUE (v2->onWheelCalled);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, MouseCancel)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto v1 = new MouseEventCheckView ();
|
||||
CRect r1 (0, 0, 50, 50);
|
||||
v1->setViewSize (r1);
|
||||
v1->setMouseableArea (r1);
|
||||
container->addView (v1);
|
||||
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (container, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::Handled);
|
||||
EXPECT_TRUE (v1->mouseDownCalled);
|
||||
EXPECT_EQ (dispatchMouseCancelEvent (container), EventConsumeState::Handled);
|
||||
EXPECT_TRUE (v1->mouseCancelCalled);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, DragEvents)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto v1 = new MouseEventCheckView ();
|
||||
auto v2 = new MouseEventCheckView ();
|
||||
CRect r1 (0, 0, 50, 50);
|
||||
CRect r2 (50, 0, 100, 50);
|
||||
v1->setViewSize (r1);
|
||||
v1->setMouseableArea (r1);
|
||||
v2->setViewSize (r2);
|
||||
v2->setMouseableArea (r2);
|
||||
container->addView (v1);
|
||||
container->addView (v2);
|
||||
|
||||
DragEventData data;
|
||||
data.drag = nullptr;
|
||||
data.pos = CPoint (10, 10);
|
||||
data.modifiers.clear ();
|
||||
|
||||
auto dropTarget = container->getDropTarget ();
|
||||
dropTarget->onDragEnter (data);
|
||||
EXPECT (v1->onDragEnterCalled);
|
||||
EXPECT (v2->onDragEnterCalled == false);
|
||||
dropTarget->onDragMove (data);
|
||||
EXPECT (v1->onDragMoveCalled);
|
||||
EXPECT (v2->onDragMoveCalled == false);
|
||||
dropTarget->onDragLeave (data);
|
||||
EXPECT (v1->onDragLeaveCalled);
|
||||
EXPECT (v2->onDragLeaveCalled == false);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, DragMoveBetweenTwoViews)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto v1 = new MouseEventCheckView ();
|
||||
auto v2 = new MouseEventCheckView ();
|
||||
CRect r1 (0, 0, 50, 50);
|
||||
CRect r2 (50, 0, 100, 50);
|
||||
v1->setViewSize (r1);
|
||||
v1->setMouseableArea (r1);
|
||||
v2->setViewSize (r2);
|
||||
v2->setMouseableArea (r2);
|
||||
container->addView (v1);
|
||||
container->addView (v2);
|
||||
|
||||
DragEventData data;
|
||||
data.drag = nullptr;
|
||||
data.pos = CPoint (10, 10);
|
||||
data.modifiers.clear ();
|
||||
|
||||
auto dropTarget = container->getDropTarget ();
|
||||
dropTarget->onDragEnter (data);
|
||||
EXPECT (v1->onDragEnterCalled);
|
||||
EXPECT (v2->onDragEnterCalled == false);
|
||||
data.pos (60, 10);
|
||||
dropTarget->onDragMove (data);
|
||||
EXPECT (v1->onDragLeaveCalled);
|
||||
EXPECT (v2->onDragEnterCalled);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest,
|
||||
MouseDownOnTransparentViewWithoutMouseSupportHidingSubviewWithMouseSupport)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
CRect r1 (0, 0, 50, 50);
|
||||
auto v1 = new MouseEventCheckView ();
|
||||
auto v2 = new CView (r1);
|
||||
v2->setTransparency (false);
|
||||
v1->setViewSize (r1);
|
||||
v1->setMouseableArea (r1);
|
||||
container->addView (v1);
|
||||
container->addView (v2);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseDownEvent> (container, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_FALSE (v1->mouseDownCalled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseMoveEvent> (container, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_FALSE (v1->mouseMovedCalled);
|
||||
EXPECT_EQ (dispatchMouseEvent<MouseUpEvent> (container, {10., 10.}, MouseButton::Left),
|
||||
EventConsumeState::NotHandled);
|
||||
EXPECT_FALSE (v1->mouseUpCalled);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, GetViewsAt)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto v1 = new TestView1 ();
|
||||
auto v2 = new TestView1 ();
|
||||
auto c1 = new CViewContainer (CRect (0, 0, 10, 10));
|
||||
auto v1c1 = new TestView1 ();
|
||||
v1c1->setVisible (false);
|
||||
auto v2c1 = new TestView1 ();
|
||||
c1->addView (v1c1);
|
||||
c1->addView (v2c1);
|
||||
v2->setMouseEnabled (false);
|
||||
container->addView (v1);
|
||||
container->addView (v2);
|
||||
container->addView (c1);
|
||||
CViewContainer::ViewList views;
|
||||
container->getViewsAt (CPoint (0, 0), views, GetViewOptions (GetViewOptions::kNone));
|
||||
EXPECT (views.size () == 2);
|
||||
views.clear ();
|
||||
container->getViewsAt (CPoint (0, 0), views, GetViewOptions (GetViewOptions::kMouseEnabled));
|
||||
EXPECT (views.size () == 1);
|
||||
views.clear ();
|
||||
container->getViewsAt (CPoint (0, 0), views,
|
||||
GetViewOptions (GetViewOptions::kIncludeViewContainer));
|
||||
EXPECT (views.size () == 3);
|
||||
views.clear ();
|
||||
container->getViewsAt (CPoint (0, 0), views, GetViewOptions (GetViewOptions::kDeep));
|
||||
EXPECT (views.size () == 3);
|
||||
views.clear ();
|
||||
container->getViewsAt (
|
||||
CPoint (0, 0), views,
|
||||
GetViewOptions (GetViewOptions::kDeep | GetViewOptions::kIncludeInvisible));
|
||||
EXPECT (views.size () == 4);
|
||||
}
|
||||
|
||||
TEST_CASE (CViewContainerTest, GetContainerAt)
|
||||
{
|
||||
auto& container = TEST_SUITE_GET_STORAGE (SharedPointer<CViewContainer>);
|
||||
|
||||
auto c1 = new CViewContainer (CRect (0, 0, 10, 10));
|
||||
auto c2 = new CViewContainer (CRect (0, 0, 10, 10));
|
||||
auto c3 = new CViewContainer (CRect (0, 0, 10, 10));
|
||||
c2->setMouseEnabled (false);
|
||||
c3->setVisible (false);
|
||||
c2->addView (c3);
|
||||
container->addView (c1);
|
||||
container->addView (c2);
|
||||
auto res = container->getContainerAt (CPoint (0, 0), GetViewOptions (GetViewOptions::kNone));
|
||||
EXPECT (res == container);
|
||||
res = container->getContainerAt (CPoint (0, 0), GetViewOptions (GetViewOptions::kDeep));
|
||||
EXPECT (res == c2);
|
||||
res = container->getContainerAt (
|
||||
CPoint (0, 0), GetViewOptions (GetViewOptions::kDeep | GetViewOptions::kIncludeInvisible));
|
||||
EXPECT (res == c3);
|
||||
res = container->getContainerAt (
|
||||
CPoint (0, 0), GetViewOptions (GetViewOptions::kDeep | GetViewOptions::kMouseEnabled));
|
||||
EXPECT (res == c1);
|
||||
}
|
||||
|
||||
} // namespaces
|
||||
@@ -0,0 +1,205 @@
|
||||
// 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/enumbitset.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
enum class Flag
|
||||
{
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
};
|
||||
using Flags = EnumBitset<Flag>;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
enum class FlagMask : uint8_t
|
||||
{
|
||||
One = 1 << 0,
|
||||
Two = 1 << 1,
|
||||
Three = 1 << 2,
|
||||
};
|
||||
using FlagMasks = EnumBitset<FlagMask, true>;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (EnumBitsetTest, InitTest)
|
||||
{
|
||||
{
|
||||
Flags f;
|
||||
EXPECT_EQ (f.value (), 0);
|
||||
}
|
||||
{
|
||||
Flags f (Flag::Two);
|
||||
EXPECT_EQ (f.value (), 2);
|
||||
}
|
||||
{
|
||||
Flags f ({Flag::One, Flag::Two});
|
||||
EXPECT_EQ (f.value (), 3);
|
||||
}
|
||||
{
|
||||
FlagMasks f;
|
||||
EXPECT_EQ (f.value (), 0);
|
||||
}
|
||||
{
|
||||
FlagMasks f (FlagMask::Two);
|
||||
EXPECT_EQ (f.value (), 2);
|
||||
}
|
||||
{
|
||||
FlagMasks f ({FlagMask::One, FlagMask::Two});
|
||||
EXPECT_EQ (f.value (), 3);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (EnumBitsetTest, AssignmentTest)
|
||||
{
|
||||
{
|
||||
Flags f;
|
||||
f = Flag::One;
|
||||
EXPECT_EQ (f.value (), 1);
|
||||
|
||||
Flags f2 = Flag::Two;
|
||||
EXPECT_EQ (f2.value (), 2);
|
||||
|
||||
f = f2;
|
||||
EXPECT_EQ (f.value (), f2.value ());
|
||||
|
||||
f2.exlusive (Flag::Three);
|
||||
EXPECT_EQ (f2.value (), 4);
|
||||
}
|
||||
{
|
||||
FlagMasks f;
|
||||
f = FlagMask::One;
|
||||
EXPECT_EQ (f.value (), 1);
|
||||
|
||||
FlagMasks f2 = FlagMask::Two;
|
||||
EXPECT_EQ (f2.value (), 2);
|
||||
|
||||
f = f2;
|
||||
EXPECT_EQ (f.value (), f2.value ());
|
||||
|
||||
f2.exlusive (FlagMask::Three);
|
||||
EXPECT_EQ (f2.value (), 4);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (EnumBitsetTest, AddRemoveTest)
|
||||
{
|
||||
{
|
||||
Flags f;
|
||||
f.add (Flag::One);
|
||||
EXPECT_EQ (f.value (), 1);
|
||||
f.add (Flag::Two);
|
||||
EXPECT_EQ (f.value (), 3);
|
||||
f.remove (Flag::One);
|
||||
EXPECT_EQ (f.value (), 2);
|
||||
|
||||
f.clear ();
|
||||
|
||||
f |= Flag::One;
|
||||
EXPECT_EQ (f.value (), 1);
|
||||
f |= Flag::Two;
|
||||
EXPECT_EQ (f.value (), 3);
|
||||
|
||||
f ^= Flag::One;
|
||||
EXPECT_EQ (f.value (), 2);
|
||||
|
||||
f.clear ();
|
||||
|
||||
f << Flag::One;
|
||||
EXPECT_EQ (f.value (), 1);
|
||||
f << Flag::Two;
|
||||
EXPECT_EQ (f.value (), 3);
|
||||
f >> Flag::One;
|
||||
EXPECT_EQ (f.value (), 2);
|
||||
}
|
||||
{
|
||||
FlagMasks f;
|
||||
f.add (FlagMask::One);
|
||||
EXPECT_EQ (f.value (), 1);
|
||||
f.add (FlagMask::Two);
|
||||
EXPECT_EQ (f.value (), 3);
|
||||
f.remove (FlagMask::One);
|
||||
EXPECT_EQ (f.value (), 2);
|
||||
|
||||
f.clear ();
|
||||
|
||||
f |= FlagMask::One;
|
||||
EXPECT_EQ (f.value (), 1);
|
||||
f |= FlagMask::Two;
|
||||
EXPECT_EQ (f.value (), 3);
|
||||
|
||||
f ^= FlagMask::One;
|
||||
EXPECT_EQ (f.value (), 2);
|
||||
|
||||
f.clear ();
|
||||
|
||||
f << FlagMask::One;
|
||||
EXPECT_EQ (f.value (), 1);
|
||||
f << FlagMask::Two;
|
||||
EXPECT_EQ (f.value (), 3);
|
||||
f >> FlagMask::One;
|
||||
EXPECT_EQ (f.value (), 2);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (EnumBitsetTest, OperatorTest)
|
||||
{
|
||||
{
|
||||
Flags f1 = Flag::One;
|
||||
Flags f2 ({Flag::Two, Flag::Three});
|
||||
|
||||
auto f3 = f1 | Flag::Two;
|
||||
EXPECT_EQ (f3.value (), 3);
|
||||
|
||||
EXPECT_TRUE (f3 & Flag::One);
|
||||
EXPECT_TRUE (f3 & Flag::Two);
|
||||
}
|
||||
{
|
||||
FlagMasks f1 = FlagMask::One;
|
||||
FlagMasks f2 ({FlagMask::Two, FlagMask::Three});
|
||||
|
||||
auto f3 = f1 | FlagMask::Two;
|
||||
EXPECT_EQ (f3.value (), 3);
|
||||
|
||||
EXPECT_TRUE (f3 & FlagMask::One);
|
||||
EXPECT_TRUE (f3 & FlagMask::Two);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (EnumBitsetTest, EqualityTest)
|
||||
{
|
||||
{
|
||||
Flags f1 ({Flag::One, Flag::Three});
|
||||
Flags f2 ({Flag::Two, Flag::Three});
|
||||
Flags f3 ({Flag::Three, Flag::One});
|
||||
|
||||
EXPECT_TRUE (f1 != f2);
|
||||
EXPECT_TRUE (f1 == f3);
|
||||
|
||||
EXPECT_TRUE (f1.test (Flag::One));
|
||||
EXPECT_FALSE (f1.test (Flag::Two));
|
||||
}
|
||||
{
|
||||
FlagMasks f1 ({FlagMask::One, FlagMask::Three});
|
||||
FlagMasks f2 ({FlagMask::Two, FlagMask::Three});
|
||||
FlagMasks f3 ({FlagMask::Three, FlagMask::One});
|
||||
|
||||
EXPECT_TRUE (f1 != f2);
|
||||
EXPECT_TRUE (f1 == f3);
|
||||
|
||||
EXPECT_TRUE (f1.test (FlagMask::One));
|
||||
EXPECT_FALSE (f1.test (FlagMask::Two));
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // 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/events.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (EventTest, UniqueIDTest)
|
||||
{
|
||||
Event e1;
|
||||
Event e2;
|
||||
EXPECT_NE (e1.id, e2.id);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, DefaultConstructorTypeTest)
|
||||
{
|
||||
MouseEnterEvent enterEvent;
|
||||
EXPECT_EQ (enterEvent.type, EventType::MouseEnter);
|
||||
MouseExitEvent exitEvent;
|
||||
EXPECT_EQ (exitEvent.type, EventType::MouseExit);
|
||||
MouseDownEvent downEvent;
|
||||
EXPECT_EQ (downEvent.type, EventType::MouseDown);
|
||||
MouseMoveEvent moveEvent;
|
||||
EXPECT_EQ (moveEvent.type, EventType::MouseMove);
|
||||
MouseUpEvent upEvent;
|
||||
EXPECT_EQ (upEvent.type, EventType::MouseUp);
|
||||
MouseCancelEvent cancelEvent;
|
||||
EXPECT_EQ (cancelEvent.type, EventType::MouseCancel);
|
||||
MouseWheelEvent wheelEvent;
|
||||
EXPECT_EQ (wheelEvent.type, EventType::MouseWheel);
|
||||
ZoomGestureEvent zoomGestureEvent;
|
||||
EXPECT_EQ (zoomGestureEvent.type, EventType::ZoomGesture);
|
||||
KeyboardEvent keyEvent;
|
||||
EXPECT_EQ (keyEvent.type, EventType::KeyDown);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, NoEventTest)
|
||||
{
|
||||
auto& event = noEvent ();
|
||||
EXPECT_EQ (event.type, EventType::Unknown);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, ConsumedTest)
|
||||
{
|
||||
EventConsumeState consumed;
|
||||
EXPECT_FALSE (consumed);
|
||||
consumed = true;
|
||||
EXPECT_TRUE (consumed);
|
||||
consumed = false;
|
||||
EXPECT_FALSE (consumed);
|
||||
consumed = true;
|
||||
EXPECT_TRUE (consumed);
|
||||
consumed.reset ();
|
||||
EXPECT_FALSE (consumed);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastMouseEnterEventTest)
|
||||
{
|
||||
MouseEnterEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), &e);
|
||||
EXPECT_EQ (asMouseEvent (e), &e);
|
||||
EXPECT_EQ (asMouseDownEvent (e), nullptr);
|
||||
EXPECT_EQ (asModifierEvent (e), &e);
|
||||
EXPECT_EQ (asKeyboardEvent (e), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastMouseExitEventTest)
|
||||
{
|
||||
MouseExitEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), &e);
|
||||
EXPECT_EQ (asMouseEvent (e), &e);
|
||||
EXPECT_EQ (asMouseDownEvent (e), nullptr);
|
||||
EXPECT_EQ (asModifierEvent (e), &e);
|
||||
EXPECT_EQ (asKeyboardEvent (e), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastMouseDownEventTest)
|
||||
{
|
||||
MouseDownEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), &e);
|
||||
EXPECT_EQ (asMouseEvent (e), &e);
|
||||
EXPECT_EQ (asMouseDownEvent (e), &e);
|
||||
EXPECT_EQ (asModifierEvent (e), &e);
|
||||
EXPECT_EQ (asKeyboardEvent (e), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastMouseMoveEventTest)
|
||||
{
|
||||
MouseMoveEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), &e);
|
||||
EXPECT_EQ (asMouseEvent (e), &e);
|
||||
EXPECT_EQ (asMouseDownEvent (e), &e);
|
||||
EXPECT_EQ (asModifierEvent (e), &e);
|
||||
EXPECT_EQ (asKeyboardEvent (e), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastMouseUpEventTest)
|
||||
{
|
||||
MouseUpEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), &e);
|
||||
EXPECT_EQ (asMouseEvent (e), &e);
|
||||
EXPECT_EQ (asMouseDownEvent (e), &e);
|
||||
EXPECT_EQ (asModifierEvent (e), &e);
|
||||
EXPECT_EQ (asKeyboardEvent (e), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastMouseCancelEventTest)
|
||||
{
|
||||
MouseCancelEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), nullptr);
|
||||
EXPECT_EQ (asMouseEvent (e), nullptr);
|
||||
EXPECT_EQ (asMouseDownEvent (e), nullptr);
|
||||
EXPECT_EQ (asModifierEvent (e), nullptr);
|
||||
EXPECT_EQ (asKeyboardEvent (e), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastMouseWheelEventTest)
|
||||
{
|
||||
MouseWheelEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), &e);
|
||||
EXPECT_EQ (asMouseEvent (e), nullptr);
|
||||
EXPECT_EQ (asMouseDownEvent (e), nullptr);
|
||||
EXPECT_EQ (asModifierEvent (e), &e);
|
||||
EXPECT_EQ (asKeyboardEvent (e), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastZoomGestureEventTest)
|
||||
{
|
||||
ZoomGestureEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), &e);
|
||||
EXPECT_EQ (asMouseEvent (e), nullptr);
|
||||
EXPECT_EQ (asMouseDownEvent (e), nullptr);
|
||||
EXPECT_EQ (asModifierEvent (e), nullptr);
|
||||
EXPECT_EQ (asKeyboardEvent (e), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, CastKeyboardEventTest)
|
||||
{
|
||||
KeyboardEvent event;
|
||||
Event& e = event;
|
||||
EXPECT_EQ (asMousePositionEvent (e), nullptr);
|
||||
EXPECT_EQ (asMouseEvent (e), nullptr);
|
||||
EXPECT_EQ (asMouseDownEvent (e), nullptr);
|
||||
EXPECT_EQ (asModifierEvent (e), &e);
|
||||
EXPECT_EQ (asKeyboardEvent (e), &e);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, ButtonStateFromEventModifierTest)
|
||||
{
|
||||
Modifiers mods;
|
||||
EXPECT_EQ (buttonStateFromEventModifiers (mods), 0);
|
||||
mods.add (ModifierKey::Control);
|
||||
EXPECT_EQ (buttonStateFromEventModifiers (mods), kControl);
|
||||
mods.add (ModifierKey::Shift);
|
||||
EXPECT_EQ (buttonStateFromEventModifiers (mods), kControl | kShift);
|
||||
mods.add (ModifierKey::Alt);
|
||||
EXPECT_EQ (buttonStateFromEventModifiers (mods), kControl | kShift | kAlt);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, ButtonStateFromMouseEventTest)
|
||||
{
|
||||
MouseDownEvent event;
|
||||
EXPECT_EQ (buttonStateFromMouseEvent (event), 0);
|
||||
event.buttonState.set (MouseButton::Left);
|
||||
EXPECT_EQ (buttonStateFromMouseEvent (event), kLButton);
|
||||
event.buttonState.set (MouseButton::Right);
|
||||
EXPECT_EQ (buttonStateFromMouseEvent (event), kRButton);
|
||||
event.buttonState.set (MouseButton::Middle);
|
||||
EXPECT_EQ (buttonStateFromMouseEvent (event), kMButton);
|
||||
event.buttonState.set (MouseButton::Fourth);
|
||||
EXPECT_EQ (buttonStateFromMouseEvent (event), kButton4);
|
||||
event.buttonState.set (MouseButton::Fifth);
|
||||
EXPECT_EQ (buttonStateFromMouseEvent (event), kButton5);
|
||||
event.clickCount = 2;
|
||||
event.buttonState.set (MouseButton::Left);
|
||||
EXPECT_EQ (buttonStateFromMouseEvent (event), kLButton | kDoubleClick);
|
||||
event.modifiers.add (ModifierKey::Shift);
|
||||
EXPECT_EQ (buttonStateFromMouseEvent (event), kLButton | kDoubleClick | kShift);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, IgnoreFollowUpEvent)
|
||||
{
|
||||
MouseDownEvent e;
|
||||
EXPECT_FALSE (e.ignoreFollowUpMoveAndUpEvents ());
|
||||
e.ignoreFollowUpMoveAndUpEvents (true);
|
||||
EXPECT_TRUE (e.ignoreFollowUpMoveAndUpEvents ());
|
||||
EXPECT_FALSE (e.consumed);
|
||||
e.consumed = true;
|
||||
EXPECT_TRUE (e.ignoreFollowUpMoveAndUpEvents ());
|
||||
EXPECT_TRUE (e.consumed);
|
||||
}
|
||||
|
||||
TEST_CASE (EventTest, ModifiersEquality)
|
||||
{
|
||||
Modifiers altMod (ModifierKey::Alt);
|
||||
Modifiers ctrlMod (ModifierKey::Control);
|
||||
EXPECT_FALSE ((altMod == ctrlMod));
|
||||
EXPECT_TRUE ((altMod != ctrlMod));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,45 @@
|
||||
// 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/events.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
template <typename EventType>
|
||||
inline uint32_t dispatchMouseEvent (CView* view, CPoint pos, MouseEventButtonState buttons = {},
|
||||
Modifiers mods = {})
|
||||
{
|
||||
EventType event;
|
||||
event.mousePosition = pos;
|
||||
event.buttonState = buttons;
|
||||
event.modifiers = mods;
|
||||
view->dispatchEvent (event);
|
||||
return event.consumed.data;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline uint32_t dispatchMouseCancelEvent (CView* view)
|
||||
{
|
||||
MouseCancelEvent event;
|
||||
view->dispatchEvent (event);
|
||||
return event.consumed.data;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
inline uint32_t dispatchMouseWheelEvent (CView* view, CPoint pos, double deltaX, double deltaY,
|
||||
Modifiers mods = {})
|
||||
{
|
||||
MouseWheelEvent event;
|
||||
event.mousePosition = pos;
|
||||
event.deltaX = deltaX;
|
||||
event.deltaY = deltaY;
|
||||
event.modifiers = mods;
|
||||
view->dispatchEvent (event);
|
||||
return event.consumed.data;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // VSTGUI
|
||||
+1665
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
||||
// 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_DEPRECATED_METHODS
|
||||
#include "../../../lib/private/disabledeprecatedmessage.h"
|
||||
|
||||
#include "../../../lib/idependency.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
class DependentObject : public CBaseObject, public IDependency
|
||||
{
|
||||
public:
|
||||
DependentObject () : notifyCalledCount (0) {}
|
||||
|
||||
CMessageResult notify (CBaseObject* sender, IdStringPtr message) override
|
||||
{
|
||||
notifyCalledCount++;
|
||||
return kMessageNotified;
|
||||
}
|
||||
|
||||
int32_t notifyCalledCount;
|
||||
};
|
||||
|
||||
class TestObject : public CBaseObject, public IDependency
|
||||
{
|
||||
public:
|
||||
TestObject () {}
|
||||
};
|
||||
|
||||
TEST_CASE (IDependencyTest, SimpleDependency)
|
||||
{
|
||||
DependentObject dObj;
|
||||
TestObject tObj;
|
||||
tObj.addDependency (&dObj);
|
||||
tObj.changed ("Test");
|
||||
EXPECT (dObj.notifyCalledCount == 1)
|
||||
tObj.removeDependency (&dObj);
|
||||
}
|
||||
|
||||
TEST_CASE (IDependencyTest, SimpleDeferedDependency)
|
||||
{
|
||||
DependentObject dObj;
|
||||
TestObject tObj;
|
||||
tObj.addDependency (&dObj);
|
||||
tObj.deferChanges (true);
|
||||
tObj.changed ("Test");
|
||||
EXPECT (dObj.notifyCalledCount == 0)
|
||||
tObj.deferChanges (false);
|
||||
EXPECT (dObj.notifyCalledCount == 1)
|
||||
tObj.removeDependency (&dObj);
|
||||
}
|
||||
|
||||
TEST_CASE (IDependencyTest, SimpleDeferChanges)
|
||||
{
|
||||
DependentObject dObj;
|
||||
TestObject tObj;
|
||||
tObj.addDependency (&dObj);
|
||||
{
|
||||
IDependency::DeferChanges df (&tObj);
|
||||
IdStringPtr messageID = "Test";
|
||||
tObj.changed (messageID);
|
||||
tObj.changed (messageID);
|
||||
EXPECT (dObj.notifyCalledCount == 0)
|
||||
}
|
||||
EXPECT (dObj.notifyCalledCount == 1)
|
||||
tObj.removeDependency (&dObj);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
|
||||
#include "../../../lib/private/enabledeprecatedmessage.h"
|
||||
#endif // VSTGUI_ENABLE_DEPRECATED_METHODS
|
||||
+95
@@ -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 "../../../lib/pixelbuffer.h"
|
||||
#include "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
using namespace PixelBuffer;
|
||||
|
||||
TEST_CASE (PixelBufferTest, ARGB_2_RGBA)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::ARGB, Format::RGBA, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x22334411);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, ARGB_2_BGRA)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::ARGB, Format::BGRA, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x44332211);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, ARGB_2_ABGR)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::ARGB, Format::ABGR, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x11443322);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, ABGR_2_ARGB)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::ABGR, Format::ARGB, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x11443322);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, ABGR_2_RGBA)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::ABGR, Format::RGBA, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x44332211);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, ABGR_2_BGRA)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::ABGR, Format::BGRA, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x22334411);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, RGBA_2_ARGB)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::RGBA, Format::ARGB, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x22334411);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, RGBA_2_ABGR)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::RGBA, Format::ABGR, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x44332211);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, RGBA_2_BGRA)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::RGBA, Format::BGRA, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x11443322);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, BGRA_2_RGBA)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::BGRA, Format::RGBA, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x33221144);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, BGRA_2_ABGR)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::BGRA, Format::ABGR, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x22334411);
|
||||
}
|
||||
|
||||
TEST_CASE (PixelBufferTest, BGRA_2_ARGB)
|
||||
{
|
||||
uint32_t pixel = 0x11223344;
|
||||
convert (Format::BGRA, Format::ARGB, reinterpret_cast<uint8_t*> (&pixel), 4, 1, 1);
|
||||
EXPECT (pixel == 0x44332211);
|
||||
}
|
||||
|
||||
} // namespace VSTGUI
|
||||
@@ -0,0 +1,22 @@
|
||||
// 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/vstguibase.h"
|
||||
#include "../../../lib/platform/iplatformframe.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
namespace UnitTest {
|
||||
|
||||
struct PlatformParentHandle : public CBaseObject
|
||||
{
|
||||
static SharedPointer<PlatformParentHandle> create ();
|
||||
|
||||
virtual PlatformType getType () const = 0;
|
||||
virtual void* getHandle () const = 0;
|
||||
virtual void forceRedraw () = 0;
|
||||
};
|
||||
|
||||
} // UnitTest
|
||||
} // VSTGUI
|
||||
|
||||
+32
@@ -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 "platform_helper.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
namespace UnitTest {
|
||||
|
||||
SharedPointer<PlatformParentHandle> PlatformParentHandle::create ()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PlatformType PlatformParentHandle::getType () const
|
||||
{
|
||||
return PlatformType::kX11EmbedWindowID;
|
||||
}
|
||||
|
||||
void* PlatformParentHandle::getHandle () const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void PlatformParentHandle::forceRedraw ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // UnitTest
|
||||
} // VSTGUI
|
||||
|
||||
+58
@@ -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 "platform_helper.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
namespace VSTGUI {
|
||||
namespace UnitTest {
|
||||
|
||||
struct MacParentHandle : PlatformParentHandle
|
||||
{
|
||||
NSWindow* window {nil};
|
||||
|
||||
MacParentHandle ()
|
||||
{
|
||||
NSWindowStyleMask style;
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
|
||||
style = NSWindowStyleMaskTitled;
|
||||
#else
|
||||
style = NSTitledWindowMask;
|
||||
#endif
|
||||
window = [[NSWindow alloc] initWithContentRect:NSMakeRect (0, 0, 100, 100)
|
||||
styleMask:style
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
}
|
||||
|
||||
~MacParentHandle () override
|
||||
{
|
||||
[window release];
|
||||
}
|
||||
|
||||
PlatformType getType () const override
|
||||
{
|
||||
return PlatformType::kNSView;
|
||||
}
|
||||
|
||||
void* getHandle () const override
|
||||
{
|
||||
return window.contentView;
|
||||
}
|
||||
|
||||
void forceRedraw () override
|
||||
{
|
||||
[window displayIfNeeded];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SharedPointer<PlatformParentHandle> PlatformParentHandle::create ()
|
||||
{
|
||||
return owned (dynamic_cast<PlatformParentHandle*> (new MacParentHandle ()));
|
||||
}
|
||||
|
||||
} // UnitTest
|
||||
} // VSTGUI
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
// 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 "platform_helper.h"
|
||||
#include "../../../lib/platform/win32/win32support.h"
|
||||
#include <windows.h>
|
||||
|
||||
namespace VSTGUI {
|
||||
namespace UnitTest {
|
||||
|
||||
static LRESULT CALLBACK MainWndProc (HWND h, UINT m , WPARAM w, LPARAM l)
|
||||
{
|
||||
return DefWindowProc (h, m, w, l);
|
||||
}
|
||||
|
||||
BOOL InitApplication(HINSTANCE hinstance)
|
||||
{
|
||||
WNDCLASSEX wcx;
|
||||
|
||||
// Fill in the window class structure with parameters
|
||||
// that describe the main window.
|
||||
|
||||
wcx.cbSize = sizeof(wcx); // size of structure
|
||||
wcx.style = CS_HREDRAW |
|
||||
CS_VREDRAW; // redraw if size changes
|
||||
wcx.lpfnWndProc = MainWndProc; // points to window procedure
|
||||
wcx.cbClsExtra = 0; // no extra class memory
|
||||
wcx.cbWndExtra = 0; // no extra window memory
|
||||
wcx.hInstance = hinstance; // handle to instance
|
||||
wcx.hIcon = LoadIcon(NULL,
|
||||
IDI_APPLICATION); // predefined app. icon
|
||||
wcx.hCursor = LoadCursor(NULL,
|
||||
IDC_ARROW); // predefined arrow
|
||||
wcx.hbrBackground = nullptr; // white background brush
|
||||
wcx.lpszMenuName = nullptr; // name of menu resource
|
||||
wcx.lpszClassName = L"MainWClass"; // name of window class
|
||||
wcx.hIconSm = nullptr;
|
||||
|
||||
// Register the window class.
|
||||
|
||||
return RegisterClassEx(&wcx);
|
||||
}
|
||||
|
||||
struct Initializer
|
||||
{
|
||||
static Initializer& instance ()
|
||||
{
|
||||
static Initializer gInstance;
|
||||
return gInstance;
|
||||
}
|
||||
Initializer ()
|
||||
{
|
||||
InitApplication (GetInstance ());
|
||||
}
|
||||
};
|
||||
|
||||
struct WinPlatformHandle : PlatformParentHandle
|
||||
{
|
||||
HWND window{ nullptr };
|
||||
|
||||
WinPlatformHandle ()
|
||||
{
|
||||
Initializer::instance ();
|
||||
window = CreateWindow (L"MainWClass", L"Test", WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, nullptr, nullptr, GetInstance (), 0);
|
||||
}
|
||||
|
||||
~WinPlatformHandle ()
|
||||
{
|
||||
DestroyWindow (window);
|
||||
}
|
||||
|
||||
PlatformType getType () const override { return PlatformType::kHWND; }
|
||||
void* getHandle () const override { return window; };
|
||||
void forceRedraw () override {};
|
||||
};
|
||||
|
||||
SharedPointer<PlatformParentHandle> PlatformParentHandle::create()
|
||||
{
|
||||
return owned (dynamic_cast<PlatformParentHandle*> (new WinPlatformHandle ()));
|
||||
}
|
||||
|
||||
} // UnitTest
|
||||
} // VSTGUI
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// 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/tasks.h"
|
||||
#include "../unittests.h"
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_SUITE_SETUP (SerialQueueTest)
|
||||
{
|
||||
TEST_SUITE_SET_STORAGE (Tasks::Queue, Tasks::makeSerialQueue ("Test Serial Queue"));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_SUITE_TEARDOWN (SerialQueueTest)
|
||||
{
|
||||
Tasks::releaseSerialQueue (TEST_SUITE_GET_STORAGE (Tasks::Queue));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (SerialQueueTest, Validation)
|
||||
{
|
||||
const auto& serialQueue = TEST_SUITE_GET_STORAGE (Tasks::Queue);
|
||||
EXPECT_NE (serialQueue, Tasks::InvalidQueue);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (SerialQueueTest, SimpleTasks)
|
||||
{
|
||||
uint32_t numIterations = 1000u;
|
||||
uint32_t counter {0u};
|
||||
const auto& serialQueue = TEST_SUITE_GET_STORAGE (Tasks::Queue);
|
||||
auto increaseCounterFunc = [&] () {
|
||||
++counter;
|
||||
std::this_thread::yield ();
|
||||
};
|
||||
for (auto i = 0u; i < numIterations; ++i)
|
||||
Tasks::schedule (serialQueue, increaseCounterFunc);
|
||||
Tasks::waitAllTasksExecuted (serialQueue);
|
||||
EXPECT_EQ (counter, numIterations)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TEST_CASE (SerialQueueTest, scheduleSerialTasksOnBackgroundQueue)
|
||||
{
|
||||
uint32_t numIterations = 1000u;
|
||||
uint32_t counter {0u};
|
||||
const auto& serialQueue = TEST_SUITE_GET_STORAGE (Tasks::Queue);
|
||||
auto increaseCounterFunc = [&] () {
|
||||
++counter;
|
||||
};
|
||||
for (auto i = 0u; i < numIterations; ++i)
|
||||
{
|
||||
Tasks::schedule (Tasks::backgroundQueue (),
|
||||
[&] () { Tasks::schedule (serialQueue, increaseCounterFunc); });
|
||||
}
|
||||
Tasks::waitAllTasksExecuted (Tasks::backgroundQueue ());
|
||||
Tasks::waitAllTasksExecuted (serialQueue);
|
||||
EXPECT_EQ (counter, numIterations)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,124 @@
|
||||
// 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 "../unittests.h"
|
||||
|
||||
#if MAC
|
||||
#include "../../../lib/platform/mac/macstring.h"
|
||||
#endif
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
TEST_CASE (UTF8StringTest, Empty)
|
||||
{
|
||||
UTF8String str;
|
||||
EXPECT (str.empty ());
|
||||
EXPECT (str.length () == 0);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, Set)
|
||||
{
|
||||
UTF8String str;
|
||||
EXPECT (str.empty ());
|
||||
str.assign ("Test");
|
||||
EXPECT (str.empty () == false);
|
||||
EXPECT (str.data () == std::string ("Test"));
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, EqualOperator)
|
||||
{
|
||||
EXPECT (UTF8String ("bla") == "bla");
|
||||
EXPECT (UTF8String ("bla") != "uhh");
|
||||
std::string str ("bla");
|
||||
std::string str2 ("uhh");
|
||||
EXPECT (UTF8String ("bla") == str);
|
||||
EXPECT (UTF8String ("bla") != str2);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, SetOperator)
|
||||
{
|
||||
UTF8String str;
|
||||
str = "Test";
|
||||
EXPECT (str == "Test");
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, GetOperator)
|
||||
{
|
||||
UTF8String str ("Test");
|
||||
UTF8StringPtr cstr = str;
|
||||
EXPECT (cstr == std::string ("Test"));
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, CopyOperator)
|
||||
{
|
||||
UTF8String str1 ("str");
|
||||
UTF8String str2 (str1);
|
||||
EXPECT (str1 == str2);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, MoveOperator)
|
||||
{
|
||||
UTF8String str1 ("str");
|
||||
UTF8String str2 (std::move (str1));
|
||||
EXPECT (str1 != str2);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, AddOperator)
|
||||
{
|
||||
UTF8String str1 ("str");
|
||||
str1 += "ing";
|
||||
EXPECT (str1 == "string");
|
||||
|
||||
auto str2 = str1 + "1";
|
||||
EXPECT (str2 == "string1");
|
||||
EXPECT (str1 == "string");
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, Clear)
|
||||
{
|
||||
UTF8String str1 ("string");
|
||||
EXPECT (str1 == "string");
|
||||
str1.clear ();
|
||||
EXPECT (str1 == "");
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, Copy)
|
||||
{
|
||||
UTF8String str1 ("string");
|
||||
char buffer[3] {1};
|
||||
str1.copy (buffer, sizeof (buffer));
|
||||
EXPECT (buffer[0] == 's');
|
||||
EXPECT (buffer[1] == 't');
|
||||
EXPECT (buffer[2] == 0);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringTest, CodePointIterator)
|
||||
{
|
||||
UTF8String str ("\xc3\x84\xe0\xa5\xb4\xf0\xaa\x80\x9a\0"); // u8"Äॴ𪀚"
|
||||
auto charCount = 0;
|
||||
for (auto it = str.begin (); it != str.end (); ++it)
|
||||
{
|
||||
charCount++;
|
||||
}
|
||||
EXPECT (charCount == 3);
|
||||
}
|
||||
|
||||
#if MAC
|
||||
|
||||
TEST_CASE (UTF8StringTest, MacPlatformString)
|
||||
{
|
||||
UTF8String str1 ("Test");
|
||||
auto platformStr = str1.getPlatformString ();
|
||||
auto macStr = dynamic_cast<MacString*> (platformStr);
|
||||
EXPECT (macStr);
|
||||
auto cfStr = macStr->getCFString ();
|
||||
auto cfStr2 = CFStringCreateWithCString (kCFAllocatorDefault, "Test", kCFStringEncodingUTF8);
|
||||
EXPECT (CFStringCompare (cfStr, cfStr2, 0) == kCFCompareEqualTo);
|
||||
CFRelease (cfStr2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // VSTGUI
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
// 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 "../unittests.h"
|
||||
|
||||
namespace VSTGUI {
|
||||
|
||||
static UTF8StringPtr asciiStr = "This is a simple ASCII String";
|
||||
static UTF8StringPtr utf8Str =
|
||||
"\xe3\x82\xa4\xe3\x83\xb3\xe3\x82\xbf\xe3\x83\xbc\xe3\x83\x8d\xe3\x83\x83\xe3\x83\x88\xe3\x82\x92\xe3\x82\x82\xe3\x81\xa3\xe3\x81\xa8\xe5\xbf\xab\xe9\x81\xa9\xe3\x81\xab\xe3\x80\x82\0"; // u8"インターネットをもっと快適に。";
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, CalculateASCIICharacterCount)
|
||||
{
|
||||
UTF8StringView str (asciiStr);
|
||||
EXPECT (str.calculateCharacterCount () == 29);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, CalculateUTF8CharacterCount)
|
||||
{
|
||||
UTF8StringView str (utf8Str);
|
||||
EXPECT (str.calculateCharacterCount () == 15);
|
||||
UTF8StringView str2 ("\xc3\x84\xe0\xa5\xb4\xf0\xaa\x80\x9a\0"); // u8"Äॴ𪀚"
|
||||
EXPECT (str2.calculateCharacterCount () == 3);
|
||||
EXPECT (str2.calculateByteCount () == 10);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, CalculateEmptyCharacterCount)
|
||||
{
|
||||
UTF8StringView str (nullptr);
|
||||
EXPECT (str.calculateCharacterCount () == 0);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, calculateASCIIByteCount)
|
||||
{
|
||||
UTF8StringView str (asciiStr);
|
||||
EXPECT (str.calculateByteCount () == 30);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, calculateUTF8ByteCount)
|
||||
{
|
||||
UTF8StringView str (utf8Str);
|
||||
EXPECT (str.calculateByteCount () == 46);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, Contains)
|
||||
{
|
||||
UTF8StringView str (asciiStr);
|
||||
EXPECT (str.contains ("simple") == true);
|
||||
EXPECT (str.contains ("not") == false);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, EndsWith)
|
||||
{
|
||||
UTF8StringView str (asciiStr);
|
||||
EXPECT (str.endsWith ("String") == true);
|
||||
EXPECT (str.endsWith ("This") == false);
|
||||
EXPECT (str.endsWith ("This is a simple ASCII String which is longer") == false);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, DoubleConversion)
|
||||
{
|
||||
UTF8StringView str ("32.56789");
|
||||
double value = str.toDouble ();
|
||||
EXPECT (value == 32.56789);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, FloatConversion)
|
||||
{
|
||||
UTF8StringView str ("32.56789");
|
||||
float value = str.toFloat ();
|
||||
EXPECT (value == 32.56789f);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, Compare)
|
||||
{
|
||||
std::string test ("This is a simple ASCII String");
|
||||
UTF8StringView str1 (test.data ());
|
||||
UTF8StringView str2 (asciiStr);
|
||||
EXPECT (str1 == str2);
|
||||
UTF8StringView str3 (utf8Str);
|
||||
EXPECT (str1 != str3);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, ContainsCheckCase)
|
||||
{
|
||||
UTF8StringView str (asciiStr);
|
||||
EXPECT (str.contains ("simple"));
|
||||
EXPECT (str.contains ("Simple") == false);
|
||||
EXPECT (str.contains ("SiMpLe", true));
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, StartsWith)
|
||||
{
|
||||
UTF8StringView str (asciiStr);
|
||||
EXPECT (str.startsWith ("This"));
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, ToDouble)
|
||||
{
|
||||
UTF8StringView str ("5.1");
|
||||
EXPECT (str.toDouble () == 5.1);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, ToFloat)
|
||||
{
|
||||
UTF8StringView str ("5.1");
|
||||
EXPECT (str.toFloat () == 5.1f);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, toInteger)
|
||||
{
|
||||
UTF8StringView str ("5");
|
||||
EXPECT (str.toInteger () == 5);
|
||||
}
|
||||
|
||||
TEST_CASE (UTF8StringViewTest, toNumber)
|
||||
{
|
||||
UTF8StringView str ("300");
|
||||
auto res = str.toNumber<int32_t> ();
|
||||
EXPECT (res);
|
||||
EXPECT (*res == 300);
|
||||
auto res2 = str.toNumber<uint8_t> ();
|
||||
EXPECT(!res2);
|
||||
}
|
||||
|
||||
} // VSTGUI
|
||||
+75
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
+140
@@ -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
|
||||
Vendored
+159
@@ -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
|
||||
+218
@@ -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
|
||||
Vendored
+99
@@ -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
|
||||
Vendored
+1780
File diff suppressed because it is too large
Load Diff
Vendored
+118
@@ -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
|
||||
Vendored
+902
@@ -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
|
||||
+52
@@ -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 {};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
+58
@@ -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
|
||||
+43
@@ -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
|
||||
+90
@@ -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
|
||||
+94
@@ -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
|
||||
+139
@@ -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
|
||||
+36
@@ -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
|
||||
+34
@@ -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
|
||||
+186
@@ -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
|
||||
+23
@@ -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
|
||||
+34
@@ -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
|
||||
+35
@@ -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
|
||||
+48
@@ -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
|
||||
+28
@@ -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
|
||||
+32
@@ -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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user