From f2e87a71aed19603c7d2701f4b8a20cbf8b74ce2 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 14 Sep 2012 15:23:54 +0000 Subject: Update all unit tests to conform to recent naming convention changes in NuttX git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5151 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/ChangeLog.txt | 4 + NxWidgets/UnitTests/CButton/Makefile | 2 +- NxWidgets/UnitTests/CButton/cbutton_main.cxx | 155 +++++ NxWidgets/UnitTests/CButton/cbuttontest.hxx | 10 - NxWidgets/UnitTests/CButton/main.cxx | 155 ----- NxWidgets/UnitTests/CButtonArray/Makefile | 2 +- .../UnitTests/CButtonArray/cbuttonarray_main.cxx | 327 +++++++++ .../UnitTests/CButtonArray/cbuttonarraytest.hxx | 10 - NxWidgets/UnitTests/CButtonArray/main.cxx | 327 --------- NxWidgets/UnitTests/CCheckBox/Makefile | 2 +- NxWidgets/UnitTests/CCheckBox/ccheckbox_main.cxx | 209 ++++++ NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx | 10 - NxWidgets/UnitTests/CCheckBox/main.cxx | 209 ------ NxWidgets/UnitTests/CGlyphButton/Makefile | 2 +- .../UnitTests/CGlyphButton/cglyphbutton_main.cxx | 225 +++++++ .../UnitTests/CGlyphButton/cglyphbuttontest.hxx | 10 - NxWidgets/UnitTests/CGlyphButton/main.cxx | 225 ------- NxWidgets/UnitTests/CImage/Makefile | 2 +- NxWidgets/UnitTests/CImage/cimage_main.cxx | 222 ++++++ NxWidgets/UnitTests/CImage/cimagetest.hxx | 10 - NxWidgets/UnitTests/CImage/main.cxx | 222 ------ NxWidgets/UnitTests/CKeypad/Makefile | 2 +- NxWidgets/UnitTests/CKeypad/ckeypad_main.cxx | 274 ++++++++ NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx | 10 - NxWidgets/UnitTests/CKeypad/main.cxx | 274 -------- NxWidgets/UnitTests/CLabel/Makefile | 2 +- NxWidgets/UnitTests/CLabel/clabel_main.cxx | 130 ++++ NxWidgets/UnitTests/CLabel/clabeltest.hxx | 10 - NxWidgets/UnitTests/CLabel/main.cxx | 130 ---- NxWidgets/UnitTests/CLatchButton/Makefile | 2 +- .../UnitTests/CLatchButton/clatchbutton_main.cxx | 199 ++++++ .../UnitTests/CLatchButton/clatchbuttontest.hxx | 10 - NxWidgets/UnitTests/CLatchButton/main.cxx | 199 ------ NxWidgets/UnitTests/CLatchButtonArray/Makefile | 2 +- .../CLatchButtonArray/clatchbuttonarray_main.cxx | 301 +++++++++ .../CLatchButtonArray/clatchbuttonarraytest.hxx | 10 - NxWidgets/UnitTests/CLatchButtonArray/main.cxx | 301 --------- NxWidgets/UnitTests/CListBox/Makefile | 2 +- NxWidgets/UnitTests/CListBox/clistbox_main.cxx | 327 +++++++++ NxWidgets/UnitTests/CListBox/clistboxtest.hxx | 10 - NxWidgets/UnitTests/CListBox/main.cxx | 327 --------- NxWidgets/UnitTests/CProgressBar/Makefile | 2 +- .../UnitTests/CProgressBar/cprogressbar_main.cxx | 238 +++++++ .../UnitTests/CProgressBar/cprogressbartest.hxx | 10 - NxWidgets/UnitTests/CProgressBar/main.cxx | 238 ------- NxWidgets/UnitTests/CRadioButton/Makefile | 2 +- .../UnitTests/CRadioButton/cradiobutton_main.cxx | 238 +++++++ .../UnitTests/CRadioButton/cradiobuttontest.hxx | 10 - NxWidgets/UnitTests/CRadioButton/main.cxx | 238 ------- NxWidgets/UnitTests/CScrollbarHorizontal/Makefile | 2 +- .../cscrollbarhorizontaltest.hxx | 10 - NxWidgets/UnitTests/CScrollbarVertical/Makefile | 2 +- .../CScrollbarVertical/cscrollbarvertical_main.cxx | 231 +++++++ .../CScrollbarVertical/cscrollbarverticaltest.hxx | 10 - NxWidgets/UnitTests/CScrollbarVertical/main.cxx | 231 ------- NxWidgets/UnitTests/CSliderHorizonal/Makefile | 2 +- .../CSliderHorizonal/csliderhorizontal_main.cxx | 231 +++++++ .../CSliderHorizonal/csliderhorizontaltest.hxx | 10 - NxWidgets/UnitTests/CSliderHorizonal/main.cxx | 231 ------- NxWidgets/UnitTests/CSliderVertical/Makefile | 2 +- .../CSliderVertical/cslidervertical_main.cxx | 231 +++++++ .../CSliderVertical/csliderverticaltest.hxx | 10 - NxWidgets/UnitTests/CSliderVertical/main.cxx | 231 ------- NxWidgets/UnitTests/CTextBox/Makefile | 2 +- NxWidgets/UnitTests/CTextBox/ctextbox_main.cxx | 141 ++++ NxWidgets/UnitTests/CTextBox/ctextboxtest.hxx | 10 - NxWidgets/UnitTests/CTextBox/main.cxx | 141 ---- NxWidgets/UnitTests/nxwm/Makefile | 2 +- NxWidgets/UnitTests/nxwm/main.cxx | 744 --------------------- NxWidgets/UnitTests/nxwm/nxwm_main.cxx | 734 ++++++++++++++++++++ 70 files changed, 4435 insertions(+), 4611 deletions(-) create mode 100644 NxWidgets/UnitTests/CButton/cbutton_main.cxx delete mode 100644 NxWidgets/UnitTests/CButton/main.cxx create mode 100644 NxWidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx delete mode 100644 NxWidgets/UnitTests/CButtonArray/main.cxx create mode 100644 NxWidgets/UnitTests/CCheckBox/ccheckbox_main.cxx delete mode 100644 NxWidgets/UnitTests/CCheckBox/main.cxx create mode 100644 NxWidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx delete mode 100644 NxWidgets/UnitTests/CGlyphButton/main.cxx create mode 100644 NxWidgets/UnitTests/CImage/cimage_main.cxx delete mode 100644 NxWidgets/UnitTests/CImage/main.cxx create mode 100644 NxWidgets/UnitTests/CKeypad/ckeypad_main.cxx delete mode 100644 NxWidgets/UnitTests/CKeypad/main.cxx create mode 100644 NxWidgets/UnitTests/CLabel/clabel_main.cxx delete mode 100644 NxWidgets/UnitTests/CLabel/main.cxx create mode 100644 NxWidgets/UnitTests/CLatchButton/clatchbutton_main.cxx delete mode 100644 NxWidgets/UnitTests/CLatchButton/main.cxx create mode 100644 NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx delete mode 100644 NxWidgets/UnitTests/CLatchButtonArray/main.cxx create mode 100644 NxWidgets/UnitTests/CListBox/clistbox_main.cxx delete mode 100644 NxWidgets/UnitTests/CListBox/main.cxx create mode 100644 NxWidgets/UnitTests/CProgressBar/cprogressbar_main.cxx delete mode 100644 NxWidgets/UnitTests/CProgressBar/main.cxx create mode 100644 NxWidgets/UnitTests/CRadioButton/cradiobutton_main.cxx delete mode 100644 NxWidgets/UnitTests/CRadioButton/main.cxx create mode 100644 NxWidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx delete mode 100644 NxWidgets/UnitTests/CScrollbarVertical/main.cxx create mode 100644 NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontal_main.cxx delete mode 100644 NxWidgets/UnitTests/CSliderHorizonal/main.cxx create mode 100644 NxWidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx delete mode 100644 NxWidgets/UnitTests/CSliderVertical/main.cxx create mode 100644 NxWidgets/UnitTests/CTextBox/ctextbox_main.cxx delete mode 100644 NxWidgets/UnitTests/CTextBox/main.cxx delete mode 100644 NxWidgets/UnitTests/nxwm/main.cxx create mode 100644 NxWidgets/UnitTests/nxwm/nxwm_main.cxx (limited to 'NxWidgets') diff --git a/NxWidgets/ChangeLog.txt b/NxWidgets/ChangeLog.txt index b74ba32bc..cdd26cb89 100644 --- a/NxWidgets/ChangeLog.txt +++ b/NxWidgets/ChangeLog.txt @@ -159,3 +159,7 @@ recent check-ins. 1.3 2012-xx-xx Gregory Nutt + +* UnitTests/*/main.cxx: Change entry point name to be consistent + with with entry point naming conventions introduced in NuttX + 6.22. diff --git a/NxWidgets/UnitTests/CButton/Makefile b/NxWidgets/UnitTests/CButton/Makefile index 4e1ae042f..77ba7e986 100644 --- a/NxWidgets/UnitTests/CButton/Makefile +++ b/NxWidgets/UnitTests/CButton/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx cbuttontest.cxx +CXXSRCS = cbutton_main.cxx cbuttontest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CButton/cbutton_main.cxx b/NxWidgets/UnitTests/CButton/cbutton_main.cxx new file mode 100644 index 000000000..973a2cd8a --- /dev/null +++ b/NxWidgets/UnitTests/CButton/cbutton_main.cxx @@ -0,0 +1,155 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CButton/cbutton_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include + +#include + +#include "cbuttontest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static const char g_pushme[] = "Push Me"; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int cbutton_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int cbutton_main(int argc, char *argv[]) +{ + // Create an instance of the font test + + printf("cbutton_main: Create CButtonTest instance\n"); + CButtonTest *test = new CButtonTest(); + + // Connect the NX server + + printf("cbutton_main: Connect the CButtonTest instance to the NX server\n"); + if (!test->connect()) + { + printf("cbutton_main: Failed to connect the CButtonTest instance to the NX server\n"); + delete test; + return 1; + } + + // Create a window to draw into + + printf("cbutton_main: Create a Window\n"); + if (!test->createWindow()) + { + printf("cbutton_main: Failed to create a window\n"); + delete test; + return 1; + } + + // Create a CButton instance + + CButton *button = test->createButton(g_pushme); + if (!button) + { + printf("cbutton_main: Failed to create a button\n"); + delete test; + return 1; + } + + // Show the button + + printf("cbutton_main: Show the button\n"); + test->showButton(button); + + // Wait two seconds, then perform a simulated mouse click on the button + + sleep(2); + printf("cbutton_main: Click the button\n"); + test->click(); + + // Poll for the mouse click event (of course this can hang if something fails) + + bool clicked = test->poll(button); + printf("cbutton_main: Button is %s\n", clicked ? "clicked" : "released"); + + // Wait a second, then release the mouse buttone + + sleep(1); + test->release(); + + // Poll for the mouse release event (of course this can hang if something fails) + + clicked = test->poll(button); + printf("cbutton_main: Button is %s\n", clicked ? "clicked" : "released"); + + // Wait a few more seconds so that the tester can ponder the result + + sleep(3); + + // Clean up and exit + + printf("cbutton_main: Clean-up and exit\n"); + delete button; + delete test; + return 0; +} + diff --git a/NxWidgets/UnitTests/CButton/cbuttontest.hxx b/NxWidgets/UnitTests/CButton/cbuttontest.hxx index cba947b73..10465c06e 100644 --- a/NxWidgets/UnitTests/CButton/cbuttontest.hxx +++ b/NxWidgets/UnitTests/CButton/cbuttontest.hxx @@ -75,16 +75,6 @@ # define CONFIG_CBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cbutton_main -# define MAIN_STRING "cbutton_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - ///////////////////////////////////////////////////////////////////////////// // Public Classes ///////////////////////////////////////////////////////////////////////////// diff --git a/NxWidgets/UnitTests/CButton/main.cxx b/NxWidgets/UnitTests/CButton/main.cxx deleted file mode 100644 index 13e9099d9..000000000 --- a/NxWidgets/UnitTests/CButton/main.cxx +++ /dev/null @@ -1,155 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CButton/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include - -#include - -#include "cbuttontest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static const char g_pushme[] = "Push Me"; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Create an instance of the font test - - printf(MAIN_STRING "Create CButtonTest instance\n"); - CButtonTest *test = new CButtonTest(); - - // Connect the NX server - - printf(MAIN_STRING "Connect the CButtonTest instance to the NX server\n"); - if (!test->connect()) - { - printf(MAIN_STRING "Failed to connect the CButtonTest instance to the NX server\n"); - delete test; - return 1; - } - - // Create a window to draw into - - printf(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - printf(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - - // Create a CButton instance - - CButton *button = test->createButton(g_pushme); - if (!button) - { - printf(MAIN_STRING "Failed to create a button\n"); - delete test; - return 1; - } - - // Show the button - - printf(MAIN_STRING "Show the button\n"); - test->showButton(button); - - // Wait two seconds, then perform a simulated mouse click on the button - - sleep(2); - printf(MAIN_STRING "Click the button\n"); - test->click(); - - // Poll for the mouse click event (of course this can hang if something fails) - - bool clicked = test->poll(button); - printf(MAIN_STRING "Button is %s\n", clicked ? "clicked" : "released"); - - // Wait a second, then release the mouse buttone - - sleep(1); - test->release(); - - // Poll for the mouse release event (of course this can hang if something fails) - - clicked = test->poll(button); - printf(MAIN_STRING "Button is %s\n", clicked ? "clicked" : "released"); - - // Wait a few more seconds so that the tester can ponder the result - - sleep(3); - - // Clean up and exit - - printf(MAIN_STRING "Clean-up and exit\n"); - delete button; - delete test; - return 0; -} - diff --git a/NxWidgets/UnitTests/CButtonArray/Makefile b/NxWidgets/UnitTests/CButtonArray/Makefile index a37e49142..a5a33b3b0 100644 --- a/NxWidgets/UnitTests/CButtonArray/Makefile +++ b/NxWidgets/UnitTests/CButtonArray/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx cbuttonarraytest.cxx +CXXSRCS = cbuttonarray_main.cxx cbuttonarraytest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx b/NxWidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx new file mode 100644 index 000000000..c247d73e5 --- /dev/null +++ b/NxWidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx @@ -0,0 +1,327 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include + +#include + +#include "cnxstring.hxx" +#include "cbuttonarraytest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmPrevious; +static unsigned int g_mmPeak; + +static FAR const char *g_buttonLabels[BUTTONARRAY_NCOLUMNS*BUTTONARRAY_NROWS] = { + "=>", "A", "B", " g_mmPeak) + { + g_mmPeak = mmcurrent.uordblks; + } +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmPrevious = mmcurrent.uordblks; + g_mmPeak = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: checkHighlighting +///////////////////////////////////////////////////////////////////////////// + +static void checkHighlighting(CButtonArray *buttonArray) +{ + // Turn highlighting on + + buttonArray->setCursorPosition(0, 0); + buttonArray->cursor(true); + + // Then test the cursor movement + + for (int row = 0; row < BUTTONARRAY_NROWS; row++) + { + for (int column = 0; column < BUTTONARRAY_NCOLUMNS; column++) + { + // Set cursor position + + buttonArray->setCursorPosition(column, row); + + // Check cursor position + + int checkColumn; + int checkRow; + if (buttonArray->isCursorPosition(checkColumn, checkRow)) + { + printf("ERROR: Not button selected\n"); + printf(" Expected (%d,%d)\n", column, row); + } + else if (checkColumn != column || checkRow != row) + { + printf("ERROR: Wrong button selected\n"); + printf(" Expected (%d,%d)\n", column, row); + printf(" Selected (%d,%d)\n", checkColumn, checkRow); + } + + // Wait a bit so that we can see the highlighting + + usleep(500*1000); + } + } + + // Turn highlighting off + + buttonArray->cursor(false); +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int cbuttonarray_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the button array test + + printf("cbuttonarray_main: Create CButtonArrayTest instance\n"); + CButtonArrayTest *test = new CButtonArrayTest(); + updateMemoryUsage(g_mmPrevious, "After creating CButtonArrayTest"); + + // Connect the NX server + + printf("cbuttonarray_main: Connect the CButtonArrayTest instance to the NX server\n"); + if (!test->connect()) + { + printf("cbuttonarray_main: Failed to connect the CButtonArrayTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After connecting to the server"); + + // Create a window to draw into + + printf("cbuttonarray_main: Create a Window\n"); + if (!test->createWindow()) + { + printf("cbuttonarray_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After creating a window"); + + // Create a CButtonArray instance + + CButtonArray *buttonArray = test->createButtonArray(); + if (!buttonArray) + { + printf("cbuttonarray_main: Failed to create a button array\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After creating CButtonArray"); + + // Add the labels to each button + + FAR const char **ptr = g_buttonLabels; + for (int j = 0; j < BUTTONARRAY_NROWS; j++) + { + for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++) + { + printf("cbuttonarray_main: Label (%d,%d): %s\n", i, j, *ptr); + CNxString string = *ptr++; + buttonArray->setText(i, j, string); + } + } + updateMemoryUsage(g_mmPrevious, "After adding labels to the buttons"); + + // Show the button array + + printf("cbuttonarray_main: Show the button array\n"); + test->showButton(buttonArray); + sleep(1); + + // Verify that button highlighting works + + checkHighlighting(buttonArray); + updateMemoryUsage(g_mmPrevious, "After highliting"); + + // Then perform a simulated mouse click on a button in the array + + for (int j = 0; j < BUTTONARRAY_NROWS; j++) + { + for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++) + { + printf("cbuttonarray_main: Click the button (%d,%d)\n", i, j); + test->click(buttonArray, i, j); + + // Poll for the mouse click event + + test->poll(buttonArray); + + // Is anything clicked? + + int clickColumn; + int clickRow; + if (buttonArray->isButtonClicked(clickColumn, clickRow)) + { + printf("cbuttonarray_main: %s: Button (%d, %d) is clicked\n", + clickColumn == i && clickRow == j ? "OK" : "ERROR", + clickColumn, clickRow); + } + else + { + printf("cbuttonarray_main: ERROR: No button is clicked\n"); + } + + // Wait a bit, then release the mouse button + + usleep(500*1000); + test->release(buttonArray, i, j); + + // Poll for the mouse release event (of course this can hang if something fails) + + test->poll(buttonArray); + if (buttonArray->isButtonClicked(clickColumn, clickRow)) + { + printf("cbuttonarray_main: ERROR: Button (%d, %d) is clicked\n", + clickColumn, clickRow); + } + + usleep(500*1000); + } + } + updateMemoryUsage(g_mmPrevious, "After pushing buttons"); + + // Clean up and exit + + printf("cbuttonarray_main: Clean-up and exit\n"); + delete buttonArray; + updateMemoryUsage(g_mmPrevious, "After deleting the button array"); + delete test; + updateMemoryUsage(g_mmPrevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial); + return 0; +} + diff --git a/NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx b/NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx index 1a75ac2c3..b8a9e15e5 100644 --- a/NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx +++ b/NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx @@ -75,16 +75,6 @@ # define CONFIG_CBUTTONARRAYTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cbuttonarray_main -# define MAIN_STRING "cbuttonarray_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CButtonArray/main.cxx b/NxWidgets/UnitTests/CButtonArray/main.cxx deleted file mode 100644 index fa02413a4..000000000 --- a/NxWidgets/UnitTests/CButtonArray/main.cxx +++ /dev/null @@ -1,327 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CButtonArray/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include - -#include - -#include "cnxstring.hxx" -#include "cbuttonarraytest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmPrevious; -static unsigned int g_mmPeak; - -static FAR const char *g_buttonLabels[BUTTONARRAY_NCOLUMNS*BUTTONARRAY_NROWS] = { - "=>", "A", "B", " g_mmPeak) - { - g_mmPeak = mmcurrent.uordblks; - } -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmPrevious = mmcurrent.uordblks; - g_mmPeak = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: checkHighlighting -///////////////////////////////////////////////////////////////////////////// - -static void checkHighlighting(CButtonArray *buttonArray) -{ - // Turn highlighting on - - buttonArray->setCursorPosition(0, 0); - buttonArray->cursor(true); - - // Then test the cursor movement - - for (int row = 0; row < BUTTONARRAY_NROWS; row++) - { - for (int column = 0; column < BUTTONARRAY_NCOLUMNS; column++) - { - // Set cursor position - - buttonArray->setCursorPosition(column, row); - - // Check cursor position - - int checkColumn; - int checkRow; - if (buttonArray->isCursorPosition(checkColumn, checkRow)) - { - printf("ERROR: Not button selected\n"); - printf(" Expected (%d,%d)\n", column, row); - } - else if (checkColumn != column || checkRow != row) - { - printf("ERROR: Wrong button selected\n"); - printf(" Expected (%d,%d)\n", column, row); - printf(" Selected (%d,%d)\n", checkColumn, checkRow); - } - - // Wait a bit so that we can see the highlighting - - usleep(500*1000); - } - } - - // Turn highlighting off - - buttonArray->cursor(false); -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the button array test - - printf(MAIN_STRING "Create CButtonArrayTest instance\n"); - CButtonArrayTest *test = new CButtonArrayTest(); - updateMemoryUsage(g_mmPrevious, "After creating CButtonArrayTest"); - - // Connect the NX server - - printf(MAIN_STRING "Connect the CButtonArrayTest instance to the NX server\n"); - if (!test->connect()) - { - printf(MAIN_STRING "Failed to connect the CButtonArrayTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After connecting to the server"); - - // Create a window to draw into - - printf(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - printf(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After creating a window"); - - // Create a CButtonArray instance - - CButtonArray *buttonArray = test->createButtonArray(); - if (!buttonArray) - { - printf(MAIN_STRING "Failed to create a button array\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After creating CButtonArray"); - - // Add the labels to each button - - FAR const char **ptr = g_buttonLabels; - for (int j = 0; j < BUTTONARRAY_NROWS; j++) - { - for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++) - { - printf(MAIN_STRING "Label (%d,%d): %s\n", i, j, *ptr); - CNxString string = *ptr++; - buttonArray->setText(i, j, string); - } - } - updateMemoryUsage(g_mmPrevious, "After adding labels to the buttons"); - - // Show the button array - - printf(MAIN_STRING "Show the button array\n"); - test->showButton(buttonArray); - sleep(1); - - // Verify that button highlighting works - - checkHighlighting(buttonArray); - updateMemoryUsage(g_mmPrevious, "After highliting"); - - // Then perform a simulated mouse click on a button in the array - - for (int j = 0; j < BUTTONARRAY_NROWS; j++) - { - for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++) - { - printf(MAIN_STRING "Click the button (%d,%d)\n", i, j); - test->click(buttonArray, i, j); - - // Poll for the mouse click event - - test->poll(buttonArray); - - // Is anything clicked? - - int clickColumn; - int clickRow; - if (buttonArray->isButtonClicked(clickColumn, clickRow)) - { - printf(MAIN_STRING "%s: Button (%d, %d) is clicked\n", - clickColumn == i && clickRow == j ? "OK" : "ERROR", - clickColumn, clickRow); - } - else - { - printf(MAIN_STRING "ERROR: No button is clicked\n"); - } - - // Wait a bit, then release the mouse button - - usleep(500*1000); - test->release(buttonArray, i, j); - - // Poll for the mouse release event (of course this can hang if something fails) - - test->poll(buttonArray); - if (buttonArray->isButtonClicked(clickColumn, clickRow)) - { - printf(MAIN_STRING "ERROR: Button (%d, %d) is clicked\n", - clickColumn, clickRow); - } - - usleep(500*1000); - } - } - updateMemoryUsage(g_mmPrevious, "After pushing buttons"); - - // Clean up and exit - - printf(MAIN_STRING "Clean-up and exit\n"); - delete buttonArray; - updateMemoryUsage(g_mmPrevious, "After deleting the button array"); - delete test; - updateMemoryUsage(g_mmPrevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial); - return 0; -} - diff --git a/NxWidgets/UnitTests/CCheckBox/Makefile b/NxWidgets/UnitTests/CCheckBox/Makefile index 6b31286df..9b46cef8d 100644 --- a/NxWidgets/UnitTests/CCheckBox/Makefile +++ b/NxWidgets/UnitTests/CCheckBox/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx ccheckboxtest.cxx +CXXSRCS = ccheckbox_main.cxx ccheckboxtest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CCheckBox/ccheckbox_main.cxx b/NxWidgets/UnitTests/CCheckBox/ccheckbox_main.cxx new file mode 100644 index 000000000..949cbc35f --- /dev/null +++ b/NxWidgets/UnitTests/CCheckBox/ccheckbox_main.cxx @@ -0,0 +1,209 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CCheckBox/ccheckbox_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "crlepalettebitmap.hxx" +#include "glyphs.hxx" +#include "ccheckboxtest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmprevious; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int ccheckbox_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("\n%s:\n", msg); + message(" Before: %8d After: %8d Change: %8d\n\n", + previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int ccheckbox_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the checkbox test + + message("ccheckbox_main: Create CCheckBoxTest instance\n"); + CCheckBoxTest *test = new CCheckBoxTest(); + updateMemoryUsage(g_mmprevious, "After creating CCheckBoxTest"); + + // Connect the NX server + + message("ccheckbox_main: Connect the CCheckBoxTest instance to the NX server\n"); + if (!test->connect()) + { + message("ccheckbox_main: Failed to connect the CCheckBoxTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "ccheckbox_main: After connecting to the server"); + + // Create a window to draw into + + message("ccheckbox_main: Create a Window\n"); + if (!test->createWindow()) + { + message("ccheckbox_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "ccheckbox_main: After creating a window"); + + // Show the initial state of the checkbox + + test->showCheckBox(); + test->showCheckBoxState(); + sleep(1); + + // Now click the checkbox + + message("ccheckbox_main: Click 1\n"); + test->clickCheckBox(); + usleep(500*1000); + test->showCheckBoxState(); + updateMemoryUsage(g_mmprevious, "After click 1"); + usleep(500*1000); + + message("ccheckbox_main: Click 2\n"); + test->clickCheckBox(); + usleep(500*1000); + test->showCheckBoxState(); + updateMemoryUsage(g_mmprevious, "After click 2"); + usleep(500*1000); + + message("ccheckbox_main: Click 3\n"); + test->clickCheckBox(); + usleep(500*1000); + test->showCheckBoxState(); + updateMemoryUsage(g_mmprevious, "After click 3"); + sleep(2); + + // Clean up and exit + + message("ccheckbox_main: Clean-up and exit\n"); + delete test; + updateMemoryUsage(g_mmprevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + return 0; +} + diff --git a/NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx b/NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx index 73e72e282..0397b37dd 100644 --- a/NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx +++ b/NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx @@ -69,16 +69,6 @@ # define CONFIG_CCHECKBOXTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME ccheckbox_main -# define MAIN_STRING "ccheckbox_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CCheckBox/main.cxx b/NxWidgets/UnitTests/CCheckBox/main.cxx deleted file mode 100644 index e9e8b516f..000000000 --- a/NxWidgets/UnitTests/CCheckBox/main.cxx +++ /dev/null @@ -1,209 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CCheckBox/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "crlepalettebitmap.hxx" -#include "glyphs.hxx" -#include "ccheckboxtest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmprevious; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("\n%s:\n", msg); - message(" Before: %8d After: %8d Change: %8d\n\n", - previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the checkbox test - - message(MAIN_STRING "Create CCheckBoxTest instance\n"); - CCheckBoxTest *test = new CCheckBoxTest(); - updateMemoryUsage(g_mmprevious, "After creating CCheckBoxTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CCheckBoxTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CCheckBoxTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window"); - - // Show the initial state of the checkbox - - test->showCheckBox(); - test->showCheckBoxState(); - sleep(1); - - // Now click the checkbox - - message(MAIN_STRING "Click 1\n"); - test->clickCheckBox(); - usleep(500*1000); - test->showCheckBoxState(); - updateMemoryUsage(g_mmprevious, "After click 1"); - usleep(500*1000); - - message(MAIN_STRING "Click 2\n"); - test->clickCheckBox(); - usleep(500*1000); - test->showCheckBoxState(); - updateMemoryUsage(g_mmprevious, "After click 2"); - usleep(500*1000); - - message(MAIN_STRING "Click 3\n"); - test->clickCheckBox(); - usleep(500*1000); - test->showCheckBoxState(); - updateMemoryUsage(g_mmprevious, "After click 3"); - sleep(2); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete test; - updateMemoryUsage(g_mmprevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - return 0; -} - diff --git a/NxWidgets/UnitTests/CGlyphButton/Makefile b/NxWidgets/UnitTests/CGlyphButton/Makefile index 01e843555..5f2522e49 100644 --- a/NxWidgets/UnitTests/CGlyphButton/Makefile +++ b/NxWidgets/UnitTests/CGlyphButton/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx cglyphbuttontest.cxx +CXXSRCS = cglyphbutton_main.cxx cglyphbuttontest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx b/NxWidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx new file mode 100644 index 000000000..95e255dcc --- /dev/null +++ b/NxWidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx @@ -0,0 +1,225 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "cglyphbuttontest.hxx" +#include "glyphs.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmprevious; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int cglyphbutton_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("\n%s:\n", msg); + message(" Before: %8d After: %8d Change: %8d\n\n", + previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int cglyphbutton_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the font test + + message("cglyphbutton_main: Create CGlyphButtonTest instance\n"); + CGlyphButtonTest *test = new CGlyphButtonTest(); + updateMemoryUsage(g_mmprevious, "After creating CGlyphButtonTest"); + + // Connect the NX server + + message("cglyphbutton_main: Connect the CGlyphButtonTest instance to the NX server\n"); + if (!test->connect()) + { + message("cglyphbutton_main: Failed to connect the CGlyphButtonTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "After connecting to the server"); + + // Create a window to draw into + + message("cglyphbutton_main: Create a Window\n"); + if (!test->createWindow()) + { + message("cglyphbutton_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "After creating a window"); + + // Create a CGlyphButton instance + + CGlyphButton *button = test->createButton(&g_arrowDown, &g_arrowUp); + if (!button) + { + message("cglyphbutton_main: Failed to create a button\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "After creating the glyph button"); + + // Show the button + + message("cglyphbutton_main: Show the button\n"); + test->showButton(button); + updateMemoryUsage(g_mmprevious, "After showing the glyph button"); + + // Wait two seconds, then perform a simulated mouse click on the button + + sleep(2); + message("cglyphbutton_main: Click the button\n"); + test->click(); + updateMemoryUsage(g_mmprevious, "After clicking glyph button"); + + // Poll for the mouse click event (of course this can hang if something fails) + + bool clicked = test->poll(button); + message("cglyphbutton_main: Button is %s\n", clicked ? "clicked" : "released"); + + // Wait a second, then release the mouse buttone + + sleep(1); + test->release(); + updateMemoryUsage(g_mmprevious, "After releasing glyph button"); + + // Poll for the mouse release event (of course this can hang if something fails) + + clicked = test->poll(button); + message("cglyphbutton_main: Button is %s\n", clicked ? "clicked" : "released"); + + // Wait a few more seconds so that the tester can ponder the result + + sleep(3); + + // Clean up and exit + + message("cglyphbutton_main: Clean-up and exit\n"); + delete button; + updateMemoryUsage(g_mmprevious, "After deleting the glyph button"); + delete test; + updateMemoryUsage(g_mmprevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + return 0; +} + diff --git a/NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx b/NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx index 940d82a9f..b3e5bb656 100644 --- a/NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx +++ b/NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx @@ -76,16 +76,6 @@ # define CONFIG_CGLYPHBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cglyphbutton_main -# define MAIN_STRING "cglyphbutton_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CGlyphButton/main.cxx b/NxWidgets/UnitTests/CGlyphButton/main.cxx deleted file mode 100644 index 7812fa9e9..000000000 --- a/NxWidgets/UnitTests/CGlyphButton/main.cxx +++ /dev/null @@ -1,225 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CGlyphButton/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "cglyphbuttontest.hxx" -#include "glyphs.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmprevious; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("\n%s:\n", msg); - message(" Before: %8d After: %8d Change: %8d\n\n", - previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the font test - - message(MAIN_STRING "Create CGlyphButtonTest instance\n"); - CGlyphButtonTest *test = new CGlyphButtonTest(); - updateMemoryUsage(g_mmprevious, "After creating CGlyphButtonTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CGlyphButtonTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CGlyphButtonTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, "After creating a window"); - - // Create a CGlyphButton instance - - CGlyphButton *button = test->createButton(&g_arrowDown, &g_arrowUp); - if (!button) - { - message(MAIN_STRING "Failed to create a button\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, "After creating the glyph button"); - - // Show the button - - message(MAIN_STRING "Show the button\n"); - test->showButton(button); - updateMemoryUsage(g_mmprevious, "After showing the glyph button"); - - // Wait two seconds, then perform a simulated mouse click on the button - - sleep(2); - message(MAIN_STRING "Click the button\n"); - test->click(); - updateMemoryUsage(g_mmprevious, "After clicking glyph button"); - - // Poll for the mouse click event (of course this can hang if something fails) - - bool clicked = test->poll(button); - message(MAIN_STRING "Button is %s\n", clicked ? "clicked" : "released"); - - // Wait a second, then release the mouse buttone - - sleep(1); - test->release(); - updateMemoryUsage(g_mmprevious, "After releasing glyph button"); - - // Poll for the mouse release event (of course this can hang if something fails) - - clicked = test->poll(button); - message(MAIN_STRING "Button is %s\n", clicked ? "clicked" : "released"); - - // Wait a few more seconds so that the tester can ponder the result - - sleep(3); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete button; - updateMemoryUsage(g_mmprevious, "After deleting the glyph button"); - delete test; - updateMemoryUsage(g_mmprevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - return 0; -} - diff --git a/NxWidgets/UnitTests/CImage/Makefile b/NxWidgets/UnitTests/CImage/Makefile index 8db783364..46e69c495 100644 --- a/NxWidgets/UnitTests/CImage/Makefile +++ b/NxWidgets/UnitTests/CImage/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx cimagetest.cxx +CXXSRCS = cimage_main.cxx cimagetest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CImage/cimage_main.cxx b/NxWidgets/UnitTests/CImage/cimage_main.cxx new file mode 100644 index 000000000..30cf49d3e --- /dev/null +++ b/NxWidgets/UnitTests/CImage/cimage_main.cxx @@ -0,0 +1,222 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CImage/cimage_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "crlepalettebitmap.hxx" +#include "glyphs.hxx" +#include "cimagetest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static struct mallinfo g_mmInitial; +static struct mallinfo g_mmprevious; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int cimage_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: showMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void showMemoryUsage(FAR struct mallinfo *mmbefore, + FAR struct mallinfo *mmafter) +{ + message("VARIABLE BEFORE AFTER\n"); + message("======== ======== ========\n"); + message("arena %8d %8d\n", mmbefore->arena, mmafter->arena); + message("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks); + message("mxordblk %8d %8d\n", mmbefore->mxordblk, mmafter->mxordblk); + message("uordblks %8d %8d\n", mmbefore->uordblks, mmafter->uordblks); + message("fordblks %8d %8d\n", mmbefore->fordblks, mmafter->fordblks); +} + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(FAR struct mallinfo *previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("\n%s:\n", msg); + showMemoryUsage(previous, &mmcurrent); + + /* Set up for the next test */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + g_mmprevious = mmcurrent; +#else + memcpy(&g_mmprevious, &mmcurrent, sizeof(struct mallinfo)); +#endif +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ +#ifdef CONFIG_CAN_PASS_STRUCTS + g_mmInitial = mallinfo(); + g_mmprevious = g_mmInitial; +#else + (void)mallinfo(&g_mmInitial); + memcpy(&g_mmprevious, &g_mmInitial, sizeof(struct mallinfo)); +#endif +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int cimage_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the font test + + message("cimage_main: Create CImageTest instance\n"); + CImageTest *test = new CImageTest(); + updateMemoryUsage(&g_mmprevious, "After creating CImageTest"); + + // Connect the NX server + + message("cimage_main: Connect the CImageTest instance to the NX server\n"); + if (!test->connect()) + { + message("cimage_main: Failed to connect the CImageTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(&g_mmprevious, "After connecting to the server"); + + // Create a window to draw into + + message("cimage_main: Create a Window\n"); + if (!test->createWindow()) + { + message("cimage_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(&g_mmprevious, "After creating a window"); + + // Create an instance of the NuttX logo + + CRlePaletteBitmap *nuttxBitmap = new CRlePaletteBitmap(&g_nuttxBitmap); + updateMemoryUsage(&g_mmprevious, "After creating the bitmap"); + + // Create a CImage instance + + CImage *image = test->createImage(static_cast(nuttxBitmap)); + if (!image) + { + message("cimage_main: Failed to create a image\n"); + delete test; + return 1; + } + updateMemoryUsage(&g_mmprevious, "After creating CImage"); + + // Show the image + + test->showImage(image); + updateMemoryUsage(&g_mmprevious, "After showing the image"); + sleep(5); + + // Clean up and exit + + message("cimage_main: Clean-up and exit\n"); + delete image; + updateMemoryUsage(&g_mmprevious, "After deleting CImage"); + + delete nuttxBitmap; + updateMemoryUsage(&g_mmprevious, "After deleting the bitmap"); + + delete test; + updateMemoryUsage(&g_mmprevious, "After deleting the test"); + updateMemoryUsage(&g_mmInitial, "Final memory usage"); + return 0; +} + diff --git a/NxWidgets/UnitTests/CImage/cimagetest.hxx b/NxWidgets/UnitTests/CImage/cimagetest.hxx index 64592ee23..9592f2936 100644 --- a/NxWidgets/UnitTests/CImage/cimagetest.hxx +++ b/NxWidgets/UnitTests/CImage/cimagetest.hxx @@ -71,16 +71,6 @@ # define CONFIG_CIMAGETEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cimage_main -# define MAIN_STRING "cimage_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CImage/main.cxx b/NxWidgets/UnitTests/CImage/main.cxx deleted file mode 100644 index dd066b809..000000000 --- a/NxWidgets/UnitTests/CImage/main.cxx +++ /dev/null @@ -1,222 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CImage/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "crlepalettebitmap.hxx" -#include "glyphs.hxx" -#include "cimagetest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static struct mallinfo g_mmInitial; -static struct mallinfo g_mmprevious; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: showMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void showMemoryUsage(FAR struct mallinfo *mmbefore, - FAR struct mallinfo *mmafter) -{ - message("VARIABLE BEFORE AFTER\n"); - message("======== ======== ========\n"); - message("arena %8d %8d\n", mmbefore->arena, mmafter->arena); - message("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks); - message("mxordblk %8d %8d\n", mmbefore->mxordblk, mmafter->mxordblk); - message("uordblks %8d %8d\n", mmbefore->uordblks, mmafter->uordblks); - message("fordblks %8d %8d\n", mmbefore->fordblks, mmafter->fordblks); -} - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(FAR struct mallinfo *previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("\n%s:\n", msg); - showMemoryUsage(previous, &mmcurrent); - - /* Set up for the next test */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - g_mmprevious = mmcurrent; -#else - memcpy(&g_mmprevious, &mmcurrent, sizeof(struct mallinfo)); -#endif -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ -#ifdef CONFIG_CAN_PASS_STRUCTS - g_mmInitial = mallinfo(); - g_mmprevious = g_mmInitial; -#else - (void)mallinfo(&g_mmInitial); - memcpy(&g_mmprevious, &g_mmInitial, sizeof(struct mallinfo)); -#endif -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the font test - - message(MAIN_STRING "Create CImageTest instance\n"); - CImageTest *test = new CImageTest(); - updateMemoryUsage(&g_mmprevious, "After creating CImageTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CImageTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CImageTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(&g_mmprevious, "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(&g_mmprevious, "After creating a window"); - - // Create an instance of the NuttX logo - - CRlePaletteBitmap *nuttxBitmap = new CRlePaletteBitmap(&g_nuttxBitmap); - updateMemoryUsage(&g_mmprevious, "After creating the bitmap"); - - // Create a CImage instance - - CImage *image = test->createImage(static_cast(nuttxBitmap)); - if (!image) - { - message(MAIN_STRING "Failed to create a image\n"); - delete test; - return 1; - } - updateMemoryUsage(&g_mmprevious, "After creating CImage"); - - // Show the image - - test->showImage(image); - updateMemoryUsage(&g_mmprevious, "After showing the image"); - sleep(5); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete image; - updateMemoryUsage(&g_mmprevious, "After deleting CImage"); - - delete nuttxBitmap; - updateMemoryUsage(&g_mmprevious, "After deleting the bitmap"); - - delete test; - updateMemoryUsage(&g_mmprevious, "After deleting the test"); - updateMemoryUsage(&g_mmInitial, "Final memory usage"); - return 0; -} - diff --git a/NxWidgets/UnitTests/CKeypad/Makefile b/NxWidgets/UnitTests/CKeypad/Makefile index ddb8fb962..3d37c26fe 100644 --- a/NxWidgets/UnitTests/CKeypad/Makefile +++ b/NxWidgets/UnitTests/CKeypad/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx ckeypadtest.cxx +CXXSRCS = ckeypad_main.cxx ckeypadtest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CKeypad/ckeypad_main.cxx b/NxWidgets/UnitTests/CKeypad/ckeypad_main.cxx new file mode 100644 index 000000000..896ef5013 --- /dev/null +++ b/NxWidgets/UnitTests/CKeypad/ckeypad_main.cxx @@ -0,0 +1,274 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CKeypad/ckeypad_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include + +#include + +#include "cnxstring.hxx" +#include "ckeypadtest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmPrevious; +static unsigned int g_mmPeak; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int ckeypad_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("%s: Before: %8d After: %8d Change: %8d\n", + msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmPrevious = mmcurrent.uordblks; + if ((unsigned int)mmcurrent.uordblks > g_mmPeak) + { + g_mmPeak = mmcurrent.uordblks; + } +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmPrevious = mmcurrent.uordblks; + g_mmPeak = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: clickButtons +///////////////////////////////////////////////////////////////////////////// + +static void clickButtons(CKeypadTest *test, CKeypad *keypad) +{ + // Perform a simulated mouse click on a button in the keypad + + for (int j = 0; j < KEYPAD_NROWS; j++) + { + for (int i = 0; i < KEYPAD_NCOLUMNS; i++) + { + printf("clickButtons: Click the button (%d,%d)\n", i, j); + test->click(keypad, i, j); + + // Poll for the mouse click event + + test->poll(keypad); + + // Is anything clicked? + + int clickColumn; + int clickRow; + if (keypad->isButtonClicked(clickColumn, clickRow)) + { + printf("clickButtons: %s: Button (%d, %d) is clicked\n", + clickColumn == i && clickRow == j ? "OK" : "ERROR", + clickColumn, clickRow); + } + else + { + printf("clickButtons: ERROR: No button is clicked\n"); + } + + // Wait a bit, then release the mouse button + + usleep(250*1000); + test->release(keypad, i, j); + + // Poll for the mouse release event (of course this can hang if something fails) + + test->poll(keypad); + if (keypad->isButtonClicked(clickColumn, clickRow)) + { + printf("clickButtons: ERROR: Button (%d, %d) is clicked\n", + clickColumn, clickRow); + } + + usleep(500*1000); + } + } + updateMemoryUsage(g_mmPrevious, "After pushing buttons"); +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int ckeypad_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the keypad test + + printf("ckeypad_main: Create CKeypadTest instance\n"); + CKeypadTest *test = new CKeypadTest(); + updateMemoryUsage(g_mmPrevious, "After creating CKeypadTest"); + + // Connect the NX server + + printf("ckeypad_main: Connect the CKeypadTest instance to the NX server\n"); + if (!test->connect()) + { + printf("ckeypad_main: Failed to connect the CKeypadTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After connecting to the server"); + + // Create a window to draw into + + printf("ckeypad_main: Create a Window\n"); + if (!test->createWindow()) + { + printf("ckeypad_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After creating a window"); + + // Create a CKeypad instance + + CKeypad *keypad = test->createKeypad(); + if (!keypad) + { + printf("ckeypad_main: Failed to create a keypad\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After creating CKeypad"); + + // Show the keypad in alphabetic mode + + printf("ckeypad_main: Show the keypad in alphabetic mode\n"); + keypad->setKeypadMode(false); + test->showKeypad(keypad); + sleep(1); + + // Then click some buttons + + clickButtons(test, keypad); + sleep(1); + + // Show the keypad in numeric mode + + printf("ckeypad_main: Show the keypad in numeric mode\n"); + keypad->setKeypadMode(true); + sleep(1); + + // Then click some buttons + + clickButtons(test, keypad); + sleep(1); + + // Clean up and exit + + printf("ckeypad_main: Clean-up and exit\n"); + delete keypad; + updateMemoryUsage(g_mmPrevious, "After deleting the keypad"); + delete test; + updateMemoryUsage(g_mmPrevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial); + return 0; +} + diff --git a/NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx b/NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx index c1c7ba79e..d11c92375 100644 --- a/NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx +++ b/NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx @@ -72,16 +72,6 @@ # define CONFIG_CKEYPADTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME ckeypad_main -# define MAIN_STRING "ckeypad_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CKeypad/main.cxx b/NxWidgets/UnitTests/CKeypad/main.cxx deleted file mode 100644 index 1c7679ee2..000000000 --- a/NxWidgets/UnitTests/CKeypad/main.cxx +++ /dev/null @@ -1,274 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CKeypad/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include - -#include - -#include "cnxstring.hxx" -#include "ckeypadtest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmPrevious; -static unsigned int g_mmPeak; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("%s: Before: %8d After: %8d Change: %8d\n", - msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmPrevious = mmcurrent.uordblks; - if ((unsigned int)mmcurrent.uordblks > g_mmPeak) - { - g_mmPeak = mmcurrent.uordblks; - } -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmPrevious = mmcurrent.uordblks; - g_mmPeak = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: clickButtons -///////////////////////////////////////////////////////////////////////////// - -static void clickButtons(CKeypadTest *test, CKeypad *keypad) -{ - // Perform a simulated mouse click on a button in the keypad - - for (int j = 0; j < KEYPAD_NROWS; j++) - { - for (int i = 0; i < KEYPAD_NCOLUMNS; i++) - { - printf(MAIN_STRING "Click the button (%d,%d)\n", i, j); - test->click(keypad, i, j); - - // Poll for the mouse click event - - test->poll(keypad); - - // Is anything clicked? - - int clickColumn; - int clickRow; - if (keypad->isButtonClicked(clickColumn, clickRow)) - { - printf(MAIN_STRING "%s: Button (%d, %d) is clicked\n", - clickColumn == i && clickRow == j ? "OK" : "ERROR", - clickColumn, clickRow); - } - else - { - printf(MAIN_STRING "ERROR: No button is clicked\n"); - } - - // Wait a bit, then release the mouse button - - usleep(250*1000); - test->release(keypad, i, j); - - // Poll for the mouse release event (of course this can hang if something fails) - - test->poll(keypad); - if (keypad->isButtonClicked(clickColumn, clickRow)) - { - printf(MAIN_STRING "ERROR: Button (%d, %d) is clicked\n", - clickColumn, clickRow); - } - - usleep(500*1000); - } - } - updateMemoryUsage(g_mmPrevious, "After pushing buttons"); -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the keypad test - - printf(MAIN_STRING "Create CKeypadTest instance\n"); - CKeypadTest *test = new CKeypadTest(); - updateMemoryUsage(g_mmPrevious, "After creating CKeypadTest"); - - // Connect the NX server - - printf(MAIN_STRING "Connect the CKeypadTest instance to the NX server\n"); - if (!test->connect()) - { - printf(MAIN_STRING "Failed to connect the CKeypadTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After connecting to the server"); - - // Create a window to draw into - - printf(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - printf(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After creating a window"); - - // Create a CKeypad instance - - CKeypad *keypad = test->createKeypad(); - if (!keypad) - { - printf(MAIN_STRING "Failed to create a keypad\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After creating CKeypad"); - - // Show the keypad in alphabetic mode - - printf(MAIN_STRING "Show the keypad in alphabetic mode\n"); - keypad->setKeypadMode(false); - test->showKeypad(keypad); - sleep(1); - - // Then click some buttons - - clickButtons(test, keypad); - sleep(1); - - // Show the keypad in numeric mode - - printf(MAIN_STRING "Show the keypad in numeric mode\n"); - keypad->setKeypadMode(true); - sleep(1); - - // Then click some buttons - - clickButtons(test, keypad); - sleep(1); - - // Clean up and exit - - printf(MAIN_STRING "Clean-up and exit\n"); - delete keypad; - updateMemoryUsage(g_mmPrevious, "After deleting the keypad"); - delete test; - updateMemoryUsage(g_mmPrevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial); - return 0; -} - diff --git a/NxWidgets/UnitTests/CLabel/Makefile b/NxWidgets/UnitTests/CLabel/Makefile index 4e49a7f5c..e04adc7de 100644 --- a/NxWidgets/UnitTests/CLabel/Makefile +++ b/NxWidgets/UnitTests/CLabel/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx clabeltest.cxx +CXXSRCS = clabel_main.cxx clabeltest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CLabel/clabel_main.cxx b/NxWidgets/UnitTests/CLabel/clabel_main.cxx new file mode 100644 index 000000000..2b800dcab --- /dev/null +++ b/NxWidgets/UnitTests/CLabel/clabel_main.cxx @@ -0,0 +1,130 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CLabel/clabel_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include + +#include + +#include "clabeltest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static const char g_hello[] = "Hello, World!"; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int clabel_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int clabel_main(int argc, char *argv[]) +{ + // Create an instance of the font test + + printf("clabel_main: Create CLabelTest instance\n"); + CLabelTest *test = new CLabelTest(); + + // Connect the NX server + + printf("clabel_main: Connect the CLabelTest instance to the NX server\n"); + if (!test->connect()) + { + printf("clabel_main: Failed to connect the CLabelTest instance to the NX server\n"); + delete test; + return 1; + } + + // Create a window to draw into + + printf("clabel_main: Create a Window\n"); + if (!test->createWindow()) + { + printf("clabel_main: Failed to create a window\n"); + delete test; + return 1; + } + + // Create a CLabel instance + + CLabel *label = test->createLabel(g_hello); + if (!label) + { + printf("clabel_main: Failed to create a label\n"); + delete test; + return 1; + } + + // Show the label + + test->showLabel(label); + sleep(5); + + // Clean up and exit + + printf("clabel_main: Clean-up and exit\n"); + delete label; + delete test; + return 0; +} + diff --git a/NxWidgets/UnitTests/CLabel/clabeltest.hxx b/NxWidgets/UnitTests/CLabel/clabeltest.hxx index f7e13fdfb..47bb7684b 100644 --- a/NxWidgets/UnitTests/CLabel/clabeltest.hxx +++ b/NxWidgets/UnitTests/CLabel/clabeltest.hxx @@ -75,16 +75,6 @@ # define CONFIG_CLABELTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME clabel_main -# define MAIN_STRING "clabel_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - ///////////////////////////////////////////////////////////////////////////// // Public Classes ///////////////////////////////////////////////////////////////////////////// diff --git a/NxWidgets/UnitTests/CLabel/main.cxx b/NxWidgets/UnitTests/CLabel/main.cxx deleted file mode 100644 index 953e6afbc..000000000 --- a/NxWidgets/UnitTests/CLabel/main.cxx +++ /dev/null @@ -1,130 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CLabel/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include - -#include - -#include "clabeltest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static const char g_hello[] = "Hello, World!"; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Create an instance of the font test - - printf(MAIN_STRING "Create CLabelTest instance\n"); - CLabelTest *test = new CLabelTest(); - - // Connect the NX server - - printf(MAIN_STRING "Connect the CLabelTest instance to the NX server\n"); - if (!test->connect()) - { - printf(MAIN_STRING "Failed to connect the CLabelTest instance to the NX server\n"); - delete test; - return 1; - } - - // Create a window to draw into - - printf(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - printf(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - - // Create a CLabel instance - - CLabel *label = test->createLabel(g_hello); - if (!label) - { - printf(MAIN_STRING "Failed to create a label\n"); - delete test; - return 1; - } - - // Show the label - - test->showLabel(label); - sleep(5); - - // Clean up and exit - - printf(MAIN_STRING "Clean-up and exit\n"); - delete label; - delete test; - return 0; -} - diff --git a/NxWidgets/UnitTests/CLatchButton/Makefile b/NxWidgets/UnitTests/CLatchButton/Makefile index d953c3e99..7444c50be 100644 --- a/NxWidgets/UnitTests/CLatchButton/Makefile +++ b/NxWidgets/UnitTests/CLatchButton/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx clatchbuttontest.cxx +CXXSRCS = clatchbutton_main.cxx clatchbuttontest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CLatchButton/clatchbutton_main.cxx b/NxWidgets/UnitTests/CLatchButton/clatchbutton_main.cxx new file mode 100644 index 000000000..13ed0613e --- /dev/null +++ b/NxWidgets/UnitTests/CLatchButton/clatchbutton_main.cxx @@ -0,0 +1,199 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CLatchButton/clatchbutton_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include + +#include + +#include "clatchbuttontest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static const char g_pushme[] = "Push Me"; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int clatchbutton_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: showButtonState +///////////////////////////////////////////////////////////////////////////// + +static void showButtonState(CLatchButton *button, bool &clicked, bool &latched) +{ + bool nowClicked = button->isClicked(); + bool nowLatched = button->isLatched(); + + printf("showButtonState: Button state: %s and %s\n", + nowClicked ? "clicked" : "released", + nowLatched ? "latched" : "unlatched"); + + if (clicked != nowClicked || latched != nowLatched) + { + printf("showButtonState: ERROR: Expected %s and %s\n", + clicked ? "clicked" : "released", + latched ? "latched" : "unlatched"); + + clicked = nowClicked; + latched = nowLatched; + } +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int clatchbutton_main(int argc, char *argv[]) +{ + // Create an instance of the font test + + printf("clatchbutton_main: Create CLatchButtonTest instance\n"); + CLatchButtonTest *test = new CLatchButtonTest(); + + // Connect the NX server + + printf("clatchbutton_main: Connect the CLatchButtonTest instance to the NX server\n"); + if (!test->connect()) + { + printf("clatchbutton_main: Failed to connect the CLatchButtonTest instance to the NX server\n"); + delete test; + return 1; + } + + // Create a window to draw into + + printf("clatchbutton_main: Create a Window\n"); + if (!test->createWindow()) + { + printf("clatchbutton_main: Failed to create a window\n"); + delete test; + return 1; + } + + // Create a CLatchButton instance + + CLatchButton *button = test->createButton(g_pushme); + if (!button) + { + printf("clatchbutton_main: Failed to create a button\n"); + delete test; + return 1; + } + + // Show the button + + printf("clatchbutton_main: Show the button\n"); + test->showButton(button); + + bool clicked = false; + bool latched = false; + showButtonState(button, clicked, latched); + + // Toggle the button state a few times + + for (int i = 0; i < 8; i++) + { + // Wait two seconds, then perform a simulated mouse click on the button + + sleep(2); + printf("clatchbutton_main: Click the button\n"); + test->click(); + test->poll(button); + + // Test the button state it should be clicked with the latch state + // toggled + + clicked = true; + latched = !latched; + showButtonState(button, clicked, latched); + + // And release the button after 0.5 seconds + + usleep(500 * 1000); + printf("clatchbutton_main: Release the button\n"); + test->release(); + test->poll(button); + + // Test the button state it should be unclicked with the latch state + // unchanged + + clicked = false; + showButtonState(button, clicked, latched); + fflush(stdout); + } + + // Wait a few more seconds so that the tester can ponder the result + + sleep(3); + + // Clean up and exit + + printf("clatchbutton_main: Clean-up and exit\n"); + delete button; + delete test; + return 0; +} + diff --git a/NxWidgets/UnitTests/CLatchButton/clatchbuttontest.hxx b/NxWidgets/UnitTests/CLatchButton/clatchbuttontest.hxx index 62405ac88..783b1a57c 100644 --- a/NxWidgets/UnitTests/CLatchButton/clatchbuttontest.hxx +++ b/NxWidgets/UnitTests/CLatchButton/clatchbuttontest.hxx @@ -75,16 +75,6 @@ # define CONFIG_CLATCHBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME clatchbutton_main -# define MAIN_STRING "clatchbutton_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - ///////////////////////////////////////////////////////////////////////////// // Public Classes ///////////////////////////////////////////////////////////////////////////// diff --git a/NxWidgets/UnitTests/CLatchButton/main.cxx b/NxWidgets/UnitTests/CLatchButton/main.cxx deleted file mode 100644 index d51f613c1..000000000 --- a/NxWidgets/UnitTests/CLatchButton/main.cxx +++ /dev/null @@ -1,199 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CLatchButton/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include - -#include - -#include "clatchbuttontest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static const char g_pushme[] = "Push Me"; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: showButtonState -///////////////////////////////////////////////////////////////////////////// - -static void showButtonState(CLatchButton *button, bool &clicked, bool &latched) -{ - bool nowClicked = button->isClicked(); - bool nowLatched = button->isLatched(); - - printf(MAIN_STRING "Button state: %s and %s\n", - nowClicked ? "clicked" : "released", - nowLatched ? "latched" : "unlatched"); - - if (clicked != nowClicked || latched != nowLatched) - { - printf(MAIN_STRING "ERROR: Expected %s and %s\n", - clicked ? "clicked" : "released", - latched ? "latched" : "unlatched"); - - clicked = nowClicked; - latched = nowLatched; - } -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Create an instance of the font test - - printf(MAIN_STRING "Create CLatchButtonTest instance\n"); - CLatchButtonTest *test = new CLatchButtonTest(); - - // Connect the NX server - - printf(MAIN_STRING "Connect the CLatchButtonTest instance to the NX server\n"); - if (!test->connect()) - { - printf(MAIN_STRING "Failed to connect the CLatchButtonTest instance to the NX server\n"); - delete test; - return 1; - } - - // Create a window to draw into - - printf(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - printf(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - - // Create a CLatchButton instance - - CLatchButton *button = test->createButton(g_pushme); - if (!button) - { - printf(MAIN_STRING "Failed to create a button\n"); - delete test; - return 1; - } - - // Show the button - - printf(MAIN_STRING "Show the button\n"); - test->showButton(button); - - bool clicked = false; - bool latched = false; - showButtonState(button, clicked, latched); - - // Toggle the button state a few times - - for (int i = 0; i < 8; i++) - { - // Wait two seconds, then perform a simulated mouse click on the button - - sleep(2); - printf(MAIN_STRING "Click the button\n"); - test->click(); - test->poll(button); - - // Test the button state it should be clicked with the latch state - // toggled - - clicked = true; - latched = !latched; - showButtonState(button, clicked, latched); - - // And release the button after 0.5 seconds - - usleep(500 * 1000); - printf(MAIN_STRING "Release the button\n"); - test->release(); - test->poll(button); - - // Test the button state it should be unclicked with the latch state - // unchanged - - clicked = false; - showButtonState(button, clicked, latched); - fflush(stdout); - } - - // Wait a few more seconds so that the tester can ponder the result - - sleep(3); - - // Clean up and exit - - printf(MAIN_STRING "Clean-up and exit\n"); - delete button; - delete test; - return 0; -} - diff --git a/NxWidgets/UnitTests/CLatchButtonArray/Makefile b/NxWidgets/UnitTests/CLatchButtonArray/Makefile index ddd44f8b3..a6ac9118b 100644 --- a/NxWidgets/UnitTests/CLatchButtonArray/Makefile +++ b/NxWidgets/UnitTests/CLatchButtonArray/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx clatchbuttonarraytest.cxx +CXXSRCS = clatchbuttonarray_main.cxx clatchbuttonarraytest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx b/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx new file mode 100644 index 000000000..ad7646560 --- /dev/null +++ b/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx @@ -0,0 +1,301 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarry_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include + +#include + +#include "cnxstring.hxx" +#include "clatchbuttonarraytest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmPrevious; +static unsigned int g_mmPeak; + +static FAR const char *g_buttonLabels[BUTTONARRAY_NCOLUMNS*BUTTONARRAY_NROWS] = { + "=>", "A", "B", "isThisButtonClicked(i,j); + bool nowLatched = buttonArray->isThisButtonLatched(i,j); + + printf("showButtonState: Button(%d,%d) state: %s and %s\n", + i, j, + nowClicked ? "clicked" : "released", + nowLatched ? "latched" : "unlatched"); + + if (clicked != nowClicked || latched != nowLatched) + { + printf("showButtonState: ERROR: Expected %s and %s\n", + clicked ? "clicked" : "released", + latched ? "latched" : "unlatched"); + + clicked = nowClicked; + latched = nowLatched; + } +} + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("%s: Before: %8d After: %8d Change: %8d\n", + msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmPrevious = mmcurrent.uordblks; + if ((unsigned int)mmcurrent.uordblks > g_mmPeak) + { + g_mmPeak = mmcurrent.uordblks; + } +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmPrevious = mmcurrent.uordblks; + g_mmPeak = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int clatchbuttonarray_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the button array test + + printf("clatchbuttonarray_main: Create CLatchButtonArrayTest instance\n"); + CLatchButtonArrayTest *test = new CLatchButtonArrayTest(); + updateMemoryUsage(g_mmPrevious, "After creating CLatchButtonArrayTest"); + + // Connect the NX server + + printf("clatchbuttonarray_main: Connect the CLatchButtonArrayTest instance to the NX server\n"); + if (!test->connect()) + { + printf("clatchbuttonarray_main: Failed to connect the CLatchButtonArrayTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After connecting to the server"); + + // Create a window to draw into + + printf("clatchbuttonarray_main: Create a Window\n"); + if (!test->createWindow()) + { + printf("clatchbuttonarray_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After creating a window"); + + // Create a CLatchButtonArray instance + + CLatchButtonArray *buttonArray = test->createButtonArray(); + if (!buttonArray) + { + printf("clatchbuttonarray_main: Failed to create a button array\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "After creating CLatchButtonArray"); + + // Add the labels to each button + + FAR const char **ptr = g_buttonLabels; + for (int j = 0; j < BUTTONARRAY_NROWS; j++) + { + for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++) + { + printf("clatchbuttonarray_main: Label (%d,%d): %s\n", i, j, *ptr); + CNxString string = *ptr++; + buttonArray->setText(i, j, string); + } + } + updateMemoryUsage(g_mmPrevious, "After adding labels to the buttons"); + + // Show the button array + + printf("clatchbuttonarray_main: Show the button array\n"); + test->showButton(buttonArray); + sleep(1); + + // Then perform a simulated mouse click on a button in the array + + bool clicked = false; + bool latched = false; + + for (int j = 0; j < BUTTONARRAY_NROWS; j++) + { + for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++) + { + // Initially, this button should be neither clicked nor latched + + clicked = false; + latched = false; + showButtonState(buttonArray, i, j, clicked, latched); + + printf("clatchbuttonarray_main: Click the button (%d,%d)\n", i, j); + test->click(buttonArray, i, j); + + // Poll for the mouse click event + + test->poll(buttonArray); + + // Now it should be clicked and latched + + clicked = true; + latched = true; + showButtonState(buttonArray, i, j, clicked, latched); + + // Wait a bit, then release the mouse button + + usleep(200*1000); + test->release(buttonArray, i, j); + + // Poll for the mouse release event (of course this can hang if something fails) + + test->poll(buttonArray); + + // Now it should be un-clicked and latched + + clicked = false; + latched = true; + showButtonState(buttonArray, i, j, clicked, latched); + + usleep(300*1000); + } + } + updateMemoryUsage(g_mmPrevious, "After pushing buttons"); + + // Clean up and exit + + printf("clatchbuttonarray_main: Clean-up and exit\n"); + delete buttonArray; + updateMemoryUsage(g_mmPrevious, "After deleting the button array"); + delete test; + updateMemoryUsage(g_mmPrevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial); + return 0; +} + diff --git a/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx b/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx index f8642f089..98c0a3bb3 100644 --- a/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx +++ b/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx @@ -75,16 +75,6 @@ # define CONFIG_CLATCHBUTTONARRAYTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME clatchbuttonarray_main -# define MAIN_STRING "clatchbuttonarray_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CLatchButtonArray/main.cxx b/NxWidgets/UnitTests/CLatchButtonArray/main.cxx deleted file mode 100644 index d38651ae9..000000000 --- a/NxWidgets/UnitTests/CLatchButtonArray/main.cxx +++ /dev/null @@ -1,301 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CLatchButtonArray/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include - -#include - -#include "cnxstring.hxx" -#include "clatchbuttonarraytest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmPrevious; -static unsigned int g_mmPeak; - -static FAR const char *g_buttonLabels[BUTTONARRAY_NCOLUMNS*BUTTONARRAY_NROWS] = { - "=>", "A", "B", "isThisButtonClicked(i,j); - bool nowLatched = buttonArray->isThisButtonLatched(i,j); - - printf(MAIN_STRING "Button(%d,%d) state: %s and %s\n", - i, j, - nowClicked ? "clicked" : "released", - nowLatched ? "latched" : "unlatched"); - - if (clicked != nowClicked || latched != nowLatched) - { - printf(MAIN_STRING "ERROR: Expected %s and %s\n", - clicked ? "clicked" : "released", - latched ? "latched" : "unlatched"); - - clicked = nowClicked; - latched = nowLatched; - } -} - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("%s: Before: %8d After: %8d Change: %8d\n", - msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmPrevious = mmcurrent.uordblks; - if ((unsigned int)mmcurrent.uordblks > g_mmPeak) - { - g_mmPeak = mmcurrent.uordblks; - } -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmPrevious = mmcurrent.uordblks; - g_mmPeak = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the button array test - - printf(MAIN_STRING "Create CLatchButtonArrayTest instance\n"); - CLatchButtonArrayTest *test = new CLatchButtonArrayTest(); - updateMemoryUsage(g_mmPrevious, "After creating CLatchButtonArrayTest"); - - // Connect the NX server - - printf(MAIN_STRING "Connect the CLatchButtonArrayTest instance to the NX server\n"); - if (!test->connect()) - { - printf(MAIN_STRING "Failed to connect the CLatchButtonArrayTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After connecting to the server"); - - // Create a window to draw into - - printf(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - printf(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After creating a window"); - - // Create a CLatchButtonArray instance - - CLatchButtonArray *buttonArray = test->createButtonArray(); - if (!buttonArray) - { - printf(MAIN_STRING "Failed to create a button array\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, "After creating CLatchButtonArray"); - - // Add the labels to each button - - FAR const char **ptr = g_buttonLabels; - for (int j = 0; j < BUTTONARRAY_NROWS; j++) - { - for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++) - { - printf(MAIN_STRING "Label (%d,%d): %s\n", i, j, *ptr); - CNxString string = *ptr++; - buttonArray->setText(i, j, string); - } - } - updateMemoryUsage(g_mmPrevious, "After adding labels to the buttons"); - - // Show the button array - - printf(MAIN_STRING "Show the button array\n"); - test->showButton(buttonArray); - sleep(1); - - // Then perform a simulated mouse click on a button in the array - - bool clicked = false; - bool latched = false; - - for (int j = 0; j < BUTTONARRAY_NROWS; j++) - { - for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++) - { - // Initially, this button should be neither clicked nor latched - - clicked = false; - latched = false; - showButtonState(buttonArray, i, j, clicked, latched); - - printf(MAIN_STRING "Click the button (%d,%d)\n", i, j); - test->click(buttonArray, i, j); - - // Poll for the mouse click event - - test->poll(buttonArray); - - // Now it should be clicked and latched - - clicked = true; - latched = true; - showButtonState(buttonArray, i, j, clicked, latched); - - // Wait a bit, then release the mouse button - - usleep(200*1000); - test->release(buttonArray, i, j); - - // Poll for the mouse release event (of course this can hang if something fails) - - test->poll(buttonArray); - - // Now it should be un-clicked and latched - - clicked = false; - latched = true; - showButtonState(buttonArray, i, j, clicked, latched); - - usleep(300*1000); - } - } - updateMemoryUsage(g_mmPrevious, "After pushing buttons"); - - // Clean up and exit - - printf(MAIN_STRING "Clean-up and exit\n"); - delete buttonArray; - updateMemoryUsage(g_mmPrevious, "After deleting the button array"); - delete test; - updateMemoryUsage(g_mmPrevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial); - return 0; -} - diff --git a/NxWidgets/UnitTests/CListBox/Makefile b/NxWidgets/UnitTests/CListBox/Makefile index 4f933ad98..f06873817 100644 --- a/NxWidgets/UnitTests/CListBox/Makefile +++ b/NxWidgets/UnitTests/CListBox/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx clistboxtest.cxx +CXXSRCS = clistbox_main.cxx clistboxtest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CListBox/clistbox_main.cxx b/NxWidgets/UnitTests/CListBox/clistbox_main.cxx new file mode 100644 index 000000000..8711f06e8 --- /dev/null +++ b/NxWidgets/UnitTests/CListBox/clistbox_main.cxx @@ -0,0 +1,327 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CListBox/clistbox_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "clistboxtest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmPrevious; +static unsigned int g_mmPeak; + +static FAR const char *g_options[] = +{ + "American groundnut (Apios americana)", + "Azuki bean (Vigna angularis)", + "Black-eyed pea (Vigna unguiculata subsp. unguiculata)", + "Chickpea (Cicer arietinum)", + "Common bean (Phaseolus vulgaris)", + "Drumstick (Moringa oleifera)", + "Dolichos bean (Lablab purpureus)", + "Fava bean (Vicia faba)", + "Garbanzo (Cicer arietinum)", + "Green bean (Phaseolus vulgaris)", + "Guar (Cyamopsis tetragonoloba)", + "Gumbo (Abelmoschus esculentus)", + "Horse gram (Macrotyloma uniflorum)", + "Indian pea (Lathyrus sativus)", + "Lentil (Lens culinaris)", + "Lima Bean (Phaseolus lunatus)", + "Moth bean (Vigna acontifolia)", + "Mung bean (Vigna radiata)", + "Okra (Abelmoschus esculentus)", + "Pea (Pisum sativum)", + "Peanut (Arachis hypogaea)", + "Pigeon pea (Cajanus cajan)", + "Ricebean (Vigna umbellata)", + "Runner bean (Phaseolus coccineus)", + "Soybean (Glycine max)", + "Tarwi (tarhui, chocho; Lupinus mutabilis)", + "Tepary bean (Phaseolus acutifolius)", + "Urad bean (Vigna mungo)", + "Velvet bean (Mucuna pruriens)", + "Winged bean (Psophocarpus tetragonolobus)", + "Yardlong bean (Vigna unguiculata subsp. sesquipedalis)" +}; +#define NOPTIONS (sizeof(g_options)/sizeof(FAR const char *)) + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int clistbox_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("%s: Before: %8d After: %8d Change: %8d\n", + msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmPrevious = mmcurrent.uordblks; + if ((unsigned int)mmcurrent.uordblks > g_mmPeak) + { + g_mmPeak = mmcurrent.uordblks; + } +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmPrevious = mmcurrent.uordblks; + g_mmPeak = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int clistbox_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the listbox test + + message("clistbox_main: Create CListBoxTest instance\n"); + CListBoxTest *test = new CListBoxTest(); + updateMemoryUsage(g_mmPrevious, "After creating CListBoxTest"); + + // Connect the NX server + + message("clistbox_main: Connect the CListBoxTest instance to the NX server\n"); + if (!test->connect()) + { + message("clistbox_main: Failed to connect the CListBoxTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "clistbox_main: After connecting to the server"); + + // Create a window to draw into + + message("clistbox_main: Create a Window\n"); + if (!test->createWindow()) + { + message("clistbox_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "clistbox_main: After creating a window"); + + // Create a listbox + + message("clistbox_main: Create a ListBox\n"); + CListBox *listbox = test->createListBox(); + if (!listbox) + { + message("clistbox_main: Failed to create a listbox\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmPrevious, "clistbox_main: After creating a listbox"); + + // Show the initial state of the listbox + + listbox->setAllowMultipleSelections(true); + test->showListBox(listbox); + sleep(1); + + // Now add items to the list box (in reverse alphabetical order) + + message("clistbox_main: Add options to the ListBox\n"); + for (int i = NOPTIONS - 1; i >= 0; i--) + { + listbox->addOption(g_options[i],i); + test->showListBox(listbox); + message("clistbox_main: %d. New option %s\n", i, g_options[i]); + usleep(500000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmPrevious, "clistbox_main: After adding the listbox items"); + sleep(1); + + // Sort the list box + + message("clistbox_main: Sort the ListBox\n"); + listbox->sort(); + test->showListBox(listbox); + updateMemoryUsage(g_mmPrevious, "clistbox_main: After sorting the listbox"); + sleep(1); + + // Select and remove items from the listbox + + srand(1978); + int nOptions; + while ((nOptions = listbox->getOptionCount()) > 0) + { + message("clistbox_main: Option count: %d\n", nOptions); + if (nOptions <= 5) + { + message("clistbox_main: Selecting all remaining options\n"); + listbox->selectAllOptions(); + test->showListBox(listbox); + updateMemoryUsage(g_mmPrevious, "clistbox_main: After selecting all options"); + sleep(1); + + message("clistbox_main: Removing all remaining options\n"); + listbox->removeAllOptions(); + updateMemoryUsage(g_mmPrevious, "clistbox_main: After removing all options"); + test->showListBox(listbox); + } + else + { + int selected[5]; + + message("clistbox_main: Selecting five options\n"); + for (int i = 0; i < 5; i++) + { + selected[i] = ((nOptions - 1) * rand()) / MAX_RAND; + message("clistbox_main: Selecting option %d\n", selected[i]); + listbox->removeOption(selected[i]); + test->showListBox(listbox); + usleep(500000); + } + updateMemoryUsage(g_mmPrevious, "clistbox_main: After selecting five options"); + + message("clistbox_main: De-selecting options\n"); + int index; + int count = 0; + while ((index = listbox->getSelectedIndex()) >= 0) + { + message("clistbox_main: De-selecting option %d\n", index); + listbox->deselectOption(index); + test->showListBox(listbox); + count++; + usleep(500000); + } + + message("clistbox_main: %s: %d options de-selected\n", + count == 5 ? "OK" : "ERROR", count); + updateMemoryUsage(g_mmPrevious, "clistbox_main: After de-selecting options"); + + message("clistbox_main: Removing the selected options\n"); + for (int i = 0; i < 5; i++) + { + message("clistbox_main: Removing option %d\n", selected[i]); + listbox->removeOption(selected[i]); + test->showListBox(listbox); + usleep(500000); + } + updateMemoryUsage(g_mmPrevious, "clistbox_main: After removing five options"); + } + sleep(1); + } + updateMemoryUsage(g_mmPrevious, "clistbox_main: After the listbox is empty again"); + sleep(1); + + // Clean up and exit + + message("clistbox_main: Clean-up and exit\n"); + delete listbox; + updateMemoryUsage(g_mmPrevious, "After deleting the listbox"); + delete test; + updateMemoryUsage(g_mmPrevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial); + return 0; +} + diff --git a/NxWidgets/UnitTests/CListBox/clistboxtest.hxx b/NxWidgets/UnitTests/CListBox/clistboxtest.hxx index 88e41f3bf..a19a2fabc 100644 --- a/NxWidgets/UnitTests/CListBox/clistboxtest.hxx +++ b/NxWidgets/UnitTests/CListBox/clistboxtest.hxx @@ -69,16 +69,6 @@ # define CONFIG_CLISTBOXTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME clistbox_main -# define MAIN_STRING "clistbox_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CListBox/main.cxx b/NxWidgets/UnitTests/CListBox/main.cxx deleted file mode 100644 index 5783e255d..000000000 --- a/NxWidgets/UnitTests/CListBox/main.cxx +++ /dev/null @@ -1,327 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CListBox/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "clistboxtest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmPrevious; -static unsigned int g_mmPeak; - -static FAR const char *g_options[] = -{ - "American groundnut (Apios americana)", - "Azuki bean (Vigna angularis)", - "Black-eyed pea (Vigna unguiculata subsp. unguiculata)", - "Chickpea (Cicer arietinum)", - "Common bean (Phaseolus vulgaris)", - "Drumstick (Moringa oleifera)", - "Dolichos bean (Lablab purpureus)", - "Fava bean (Vicia faba)", - "Garbanzo (Cicer arietinum)", - "Green bean (Phaseolus vulgaris)", - "Guar (Cyamopsis tetragonoloba)", - "Gumbo (Abelmoschus esculentus)", - "Horse gram (Macrotyloma uniflorum)", - "Indian pea (Lathyrus sativus)", - "Lentil (Lens culinaris)", - "Lima Bean (Phaseolus lunatus)", - "Moth bean (Vigna acontifolia)", - "Mung bean (Vigna radiata)", - "Okra (Abelmoschus esculentus)", - "Pea (Pisum sativum)", - "Peanut (Arachis hypogaea)", - "Pigeon pea (Cajanus cajan)", - "Ricebean (Vigna umbellata)", - "Runner bean (Phaseolus coccineus)", - "Soybean (Glycine max)", - "Tarwi (tarhui, chocho; Lupinus mutabilis)", - "Tepary bean (Phaseolus acutifolius)", - "Urad bean (Vigna mungo)", - "Velvet bean (Mucuna pruriens)", - "Winged bean (Psophocarpus tetragonolobus)", - "Yardlong bean (Vigna unguiculata subsp. sesquipedalis)" -}; -#define NOPTIONS (sizeof(g_options)/sizeof(FAR const char *)) - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("%s: Before: %8d After: %8d Change: %8d\n", - msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmPrevious = mmcurrent.uordblks; - if ((unsigned int)mmcurrent.uordblks > g_mmPeak) - { - g_mmPeak = mmcurrent.uordblks; - } -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmPrevious = mmcurrent.uordblks; - g_mmPeak = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the listbox test - - message(MAIN_STRING "Create CListBoxTest instance\n"); - CListBoxTest *test = new CListBoxTest(); - updateMemoryUsage(g_mmPrevious, "After creating CListBoxTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CListBoxTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CListBoxTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After creating a window"); - - // Create a listbox - - message(MAIN_STRING "Create a ListBox\n"); - CListBox *listbox = test->createListBox(); - if (!listbox) - { - message(MAIN_STRING "Failed to create a listbox\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After creating a listbox"); - - // Show the initial state of the listbox - - listbox->setAllowMultipleSelections(true); - test->showListBox(listbox); - sleep(1); - - // Now add items to the list box (in reverse alphabetical order) - - message(MAIN_STRING "Add options to the ListBox\n"); - for (int i = NOPTIONS - 1; i >= 0; i--) - { - listbox->addOption(g_options[i],i); - test->showListBox(listbox); - message(MAIN_STRING "%d. New option %s\n", i, g_options[i]); - usleep(500000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After adding the listbox items"); - sleep(1); - - // Sort the list box - - message(MAIN_STRING "Sort the ListBox\n"); - listbox->sort(); - test->showListBox(listbox); - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After sorting the listbox"); - sleep(1); - - // Select and remove items from the listbox - - srand(1978); - int nOptions; - while ((nOptions = listbox->getOptionCount()) > 0) - { - message(MAIN_STRING "Option count: %d\n", nOptions); - if (nOptions <= 5) - { - message(MAIN_STRING "Selecting all remaining options\n"); - listbox->selectAllOptions(); - test->showListBox(listbox); - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After selecting all options"); - sleep(1); - - message(MAIN_STRING "Removing all remaining options\n"); - listbox->removeAllOptions(); - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After removing all options"); - test->showListBox(listbox); - } - else - { - int selected[5]; - - message(MAIN_STRING "Selecting five options\n"); - for (int i = 0; i < 5; i++) - { - selected[i] = ((nOptions - 1) * rand()) / MAX_RAND; - message(MAIN_STRING "Selecting option %d\n", selected[i]); - listbox->removeOption(selected[i]); - test->showListBox(listbox); - usleep(500000); - } - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After selecting five options"); - - message(MAIN_STRING "De-selecting options\n"); - int index; - int count = 0; - while ((index = listbox->getSelectedIndex()) >= 0) - { - message(MAIN_STRING "De-selecting option %d\n", index); - listbox->deselectOption(index); - test->showListBox(listbox); - count++; - usleep(500000); - } - - message(MAIN_STRING "%s: %d options de-selected\n", - count == 5 ? "OK" : "ERROR", count); - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After de-selecting options"); - - message(MAIN_STRING "Removing the selected options\n"); - for (int i = 0; i < 5; i++) - { - message(MAIN_STRING "Removing option %d\n", selected[i]); - listbox->removeOption(selected[i]); - test->showListBox(listbox); - usleep(500000); - } - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After removing five options"); - } - sleep(1); - } - updateMemoryUsage(g_mmPrevious, MAIN_STRING "After the listbox is empty again"); - sleep(1); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete listbox; - updateMemoryUsage(g_mmPrevious, "After deleting the listbox"); - delete test; - updateMemoryUsage(g_mmPrevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial); - return 0; -} - diff --git a/NxWidgets/UnitTests/CProgressBar/Makefile b/NxWidgets/UnitTests/CProgressBar/Makefile index a1e09ed57..5ee346b52 100644 --- a/NxWidgets/UnitTests/CProgressBar/Makefile +++ b/NxWidgets/UnitTests/CProgressBar/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx cprogressbartest.cxx +CXXSRCS = cprogressbar_main.cxx cprogressbartest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CProgressBar/cprogressbar_main.cxx b/NxWidgets/UnitTests/CProgressBar/cprogressbar_main.cxx new file mode 100644 index 000000000..cb5fa130e --- /dev/null +++ b/NxWidgets/UnitTests/CProgressBar/cprogressbar_main.cxx @@ -0,0 +1,238 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CProgressBar/cprogressbar_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "cprogressbartest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +#define MAX_PROGRESSBAR 50 + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmprevious; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int cprogressbar_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("\n%s:\n", msg); + message(" Before: %8d After: %8d Change: %8d\n\n", + previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int cprogressbar_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the checkbox test + + message("cprogressbar_main: Create CProgressBarTest instance\n"); + CProgressBarTest *test = new CProgressBarTest(); + updateMemoryUsage(g_mmprevious, "After creating CProgressBarTest"); + + // Connect the NX server + + message("cprogressbar_main: Connect the CProgressBarTest instance to the NX server\n"); + if (!test->connect()) + { + message("cprogressbar_main: Failed to connect the CProgressBarTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cprogressbar_main: After connecting to the server"); + + // Create a window to draw into + + message("cprogressbar_main: Create a Window\n"); + if (!test->createWindow()) + { + message("cprogressbar_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cprogressbar_main: After creating a window"); + + // Create a progress bar + + message("cprogressbar_main: Create a ProgressBar\n"); + CProgressBar *bar = test->createProgressBar(); + if (!bar) + { + message("cprogressbar_main: Failed to create a progress bar\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cprogressbar_main: After creating a progress bar"); + + // Set the progress bar minimum and maximum values + + bar->setMinimumValue(0); + bar->setMaximumValue(MAX_PROGRESSBAR); + bar->setValue(0); + bar->hidePercentageText(); + message("cprogressbar_main: ProgressBar range %d->%d Initial value %d\n", + bar->getMinimumValue(), bar->getMaximumValue(), + bar->getValue()); + + // Show the initial state of the checkbox + + test->showProgressBar(bar); + sleep(1); + + // Now move the progress bar up from 0 to 100% (with percentages off) + + for (int i = 0; i <= MAX_PROGRESSBAR; i++) + { + bar->setValue(i); + test->showProgressBar(bar); + message("cprogressbar_main: %d. New value %d\n", i, bar->getValue()); + usleep(1000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmprevious, "cprogressbar_main: After moving the progress bar up #1"); + usleep(500*1000); + + // Now move the progress bar up from 0 to 100% (with percentages off) + + bar->showPercentageText(); + bar->setValue(0); + test->showProgressBar(bar); + usleep(500*1000); + + for (int i = 0; i <= MAX_PROGRESSBAR; i++) + { + bar->setValue(i); + test->showProgressBar(bar); + message("cprogressbar_main: %d. New value %d\n", i, bar->getValue()); + usleep(1000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmprevious, "cprogressbar_main: After moving the progress bar up #2"); + sleep(1); + + // Clean up and exit + + message("cprogressbar_main: Clean-up and exit\n"); + delete bar; + updateMemoryUsage(g_mmprevious, "After deleting the progress bar"); + delete test; + updateMemoryUsage(g_mmprevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + return 0; +} + diff --git a/NxWidgets/UnitTests/CProgressBar/cprogressbartest.hxx b/NxWidgets/UnitTests/CProgressBar/cprogressbartest.hxx index 99312cf8f..a7a4238e7 100644 --- a/NxWidgets/UnitTests/CProgressBar/cprogressbartest.hxx +++ b/NxWidgets/UnitTests/CProgressBar/cprogressbartest.hxx @@ -69,16 +69,6 @@ # define CONFIG_CPROGRESSBARTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cprogressbar_main -# define MAIN_STRING "cprogressbar_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CProgressBar/main.cxx b/NxWidgets/UnitTests/CProgressBar/main.cxx deleted file mode 100644 index 525c509d3..000000000 --- a/NxWidgets/UnitTests/CProgressBar/main.cxx +++ /dev/null @@ -1,238 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CProgressBar/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "cprogressbartest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -#define MAX_PROGRESSBAR 50 - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmprevious; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("\n%s:\n", msg); - message(" Before: %8d After: %8d Change: %8d\n\n", - previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the checkbox test - - message(MAIN_STRING "Create CProgressBarTest instance\n"); - CProgressBarTest *test = new CProgressBarTest(); - updateMemoryUsage(g_mmprevious, "After creating CProgressBarTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CProgressBarTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CProgressBarTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window"); - - // Create a progress bar - - message(MAIN_STRING "Create a ProgressBar\n"); - CProgressBar *bar = test->createProgressBar(); - if (!bar) - { - message(MAIN_STRING "Failed to create a progress bar\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a progress bar"); - - // Set the progress bar minimum and maximum values - - bar->setMinimumValue(0); - bar->setMaximumValue(MAX_PROGRESSBAR); - bar->setValue(0); - bar->hidePercentageText(); - message(MAIN_STRING "ProgressBar range %d->%d Initial value %d\n", - bar->getMinimumValue(), bar->getMaximumValue(), - bar->getValue()); - - // Show the initial state of the checkbox - - test->showProgressBar(bar); - sleep(1); - - // Now move the progress bar up from 0 to 100% (with percentages off) - - for (int i = 0; i <= MAX_PROGRESSBAR; i++) - { - bar->setValue(i); - test->showProgressBar(bar); - message(MAIN_STRING "%d. New value %d\n", i, bar->getValue()); - usleep(1000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the progress bar up #1"); - usleep(500*1000); - - // Now move the progress bar up from 0 to 100% (with percentages off) - - bar->showPercentageText(); - bar->setValue(0); - test->showProgressBar(bar); - usleep(500*1000); - - for (int i = 0; i <= MAX_PROGRESSBAR; i++) - { - bar->setValue(i); - test->showProgressBar(bar); - message(MAIN_STRING "%d. New value %d\n", i, bar->getValue()); - usleep(1000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the progress bar up #2"); - sleep(1); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete bar; - updateMemoryUsage(g_mmprevious, "After deleting the progress bar"); - delete test; - updateMemoryUsage(g_mmprevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - return 0; -} - diff --git a/NxWidgets/UnitTests/CRadioButton/Makefile b/NxWidgets/UnitTests/CRadioButton/Makefile index f861326e9..57190e8d3 100644 --- a/NxWidgets/UnitTests/CRadioButton/Makefile +++ b/NxWidgets/UnitTests/CRadioButton/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx cradiobuttontest.cxx +CXXSRCS = cradiobutton_main.cxx cradiobuttontest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CRadioButton/cradiobutton_main.cxx b/NxWidgets/UnitTests/CRadioButton/cradiobutton_main.cxx new file mode 100644 index 000000000..0ec1ca196 --- /dev/null +++ b/NxWidgets/UnitTests/CRadioButton/cradiobutton_main.cxx @@ -0,0 +1,238 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CRadioButton/cradiobutton_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "crlepalettebitmap.hxx" +#include "glyphs.hxx" +#include "cradiobuttontest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmprevious; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int cradiobutton_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("\n%s:\n", msg); + message(" Before: %8d After: %8d Change: %8d\n\n", + previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int cradiobutton_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the radio button test + + message("cradiobutton_main: Create CRadioButtonTest instance\n"); + CRadioButtonTest *test = new CRadioButtonTest(); + updateMemoryUsage(g_mmprevious, "After creating CRadioButtonTest"); + + // Connect the NX server + + message("cradiobutton_main: Connect the CRadioButtonTest instance to the NX server\n"); + if (!test->connect()) + { + message("cradiobutton_main: Failed to connect the CRadioButtonTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cradiobutton_main: After connecting to the server"); + + // Create a window to draw into + + message("cradiobutton_main: Create a Window\n"); + if (!test->createWindow()) + { + message("cradiobutton_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cradiobutton_main: After creating a window"); + + // Create three radio buttons + + CRadioButton *button1 = test->newRadioButton(); + if (!button1) + { + message("cradiobutton_main: Failed to create radio button 1\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cradiobutton_main: After creating radio button 1"); + + CRadioButton *button2 = test->newRadioButton(); + if (!button2) + { + message("cradiobutton_main: Failed to create radio button 2\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cradiobutton_main: After creating radio button 2"); + + CRadioButton *button3 = test->newRadioButton(); + if (!button3) + { + message("cradiobutton_main: Failed to create radio button 3\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cradiobutton_main: After creating radio button 3"); + + // Show the initial state of the buttons + + test->showButtons(); + test->showButtonState(); + sleep(1); + + // Now push some buttons + + message("cradiobutton_main: Pushing button 1\n"); + test->pushButton(button1); + usleep(500*1000); + test->showButtonState(); + updateMemoryUsage(g_mmprevious, "After pushing button 1"); + usleep(500*1000); + + message("cradiobutton_main: Pushing button 2\n"); + test->pushButton(button2); + usleep(500*1000); + test->showButtonState(); + updateMemoryUsage(g_mmprevious, "After pushing button 2"); + usleep(500*1000); + + message("cradiobutton_main: Pushing button 3\n"); + test->pushButton(button3); + usleep(500*1000); + test->showButtonState(); + updateMemoryUsage(g_mmprevious, "After pushing button 3"); + sleep(2); + + // Clean up and exit + + message("cradiobutton_main: Clean-up and exit\n"); + delete test; + updateMemoryUsage(g_mmprevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + return 0; +} + diff --git a/NxWidgets/UnitTests/CRadioButton/cradiobuttontest.hxx b/NxWidgets/UnitTests/CRadioButton/cradiobuttontest.hxx index 00cded78c..540d5019b 100644 --- a/NxWidgets/UnitTests/CRadioButton/cradiobuttontest.hxx +++ b/NxWidgets/UnitTests/CRadioButton/cradiobuttontest.hxx @@ -70,16 +70,6 @@ # define CONFIG_CRADIOBUTTONTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cradiobutton_main -# define MAIN_STRING "cradiobutton_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CRadioButton/main.cxx b/NxWidgets/UnitTests/CRadioButton/main.cxx deleted file mode 100644 index d53cd4a09..000000000 --- a/NxWidgets/UnitTests/CRadioButton/main.cxx +++ /dev/null @@ -1,238 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CRadioButton/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "crlepalettebitmap.hxx" -#include "glyphs.hxx" -#include "cradiobuttontest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmprevious; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("\n%s:\n", msg); - message(" Before: %8d After: %8d Change: %8d\n\n", - previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the radio button test - - message(MAIN_STRING "Create CRadioButtonTest instance\n"); - CRadioButtonTest *test = new CRadioButtonTest(); - updateMemoryUsage(g_mmprevious, "After creating CRadioButtonTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CRadioButtonTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CRadioButtonTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window"); - - // Create three radio buttons - - CRadioButton *button1 = test->newRadioButton(); - if (!button1) - { - message(MAIN_STRING "Failed to create radio button 1\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating radio button 1"); - - CRadioButton *button2 = test->newRadioButton(); - if (!button2) - { - message(MAIN_STRING "Failed to create radio button 2\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating radio button 2"); - - CRadioButton *button3 = test->newRadioButton(); - if (!button3) - { - message(MAIN_STRING "Failed to create radio button 3\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating radio button 3"); - - // Show the initial state of the buttons - - test->showButtons(); - test->showButtonState(); - sleep(1); - - // Now push some buttons - - message(MAIN_STRING "Pushing button 1\n"); - test->pushButton(button1); - usleep(500*1000); - test->showButtonState(); - updateMemoryUsage(g_mmprevious, "After pushing button 1"); - usleep(500*1000); - - message(MAIN_STRING "Pushing button 2\n"); - test->pushButton(button2); - usleep(500*1000); - test->showButtonState(); - updateMemoryUsage(g_mmprevious, "After pushing button 2"); - usleep(500*1000); - - message(MAIN_STRING "Pushing button 3\n"); - test->pushButton(button3); - usleep(500*1000); - test->showButtonState(); - updateMemoryUsage(g_mmprevious, "After pushing button 3"); - sleep(2); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete test; - updateMemoryUsage(g_mmprevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - return 0; -} - diff --git a/NxWidgets/UnitTests/CScrollbarHorizontal/Makefile b/NxWidgets/UnitTests/CScrollbarHorizontal/Makefile index a6abb461b..191324a96 100644 --- a/NxWidgets/UnitTests/CScrollbarHorizontal/Makefile +++ b/NxWidgets/UnitTests/CScrollbarHorizontal/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx cscrollbarhorizontaltest.cxx +CXXSRCS = cscrollbarhorizontal_main.cxx cscrollbarhorizontaltest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx b/NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx index fac165033..774225091 100644 --- a/NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx +++ b/NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx @@ -69,16 +69,6 @@ # define CONFIG_CSCROLLBARHORIZONTALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cscrollbarhorizontal_main -# define MAIN_STRING "cscrollbarhorizontal_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CScrollbarVertical/Makefile b/NxWidgets/UnitTests/CScrollbarVertical/Makefile index ad7ae2a38..a2777e752 100644 --- a/NxWidgets/UnitTests/CScrollbarVertical/Makefile +++ b/NxWidgets/UnitTests/CScrollbarVertical/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx cscrollbarverticaltest.cxx +CXXSRCS = cscrollbarvertical_main.cxx cscrollbarverticaltest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx b/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx new file mode 100644 index 000000000..26dc70dbd --- /dev/null +++ b/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx @@ -0,0 +1,231 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "cscrollbarverticaltest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +#define MAX_SCROLLBAR 20 + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmprevious; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int cscrollbarvertical_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("\n%s:\n", msg); + message(" Before: %8d After: %8d Change: %8d\n\n", + previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int cscrollbarvertical_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the checkbox test + + message("cscrollbarvertical_main: Create CScrollbarVerticalTest instance\n"); + CScrollbarVerticalTest *test = new CScrollbarVerticalTest(); + updateMemoryUsage(g_mmprevious, "After creating CScrollbarVerticalTest"); + + // Connect the NX server + + message("cscrollbarvertical_main: Connect the CScrollbarVerticalTest instance to the NX server\n"); + if (!test->connect()) + { + message("cscrollbarvertical_main: Failed to connect the CScrollbarVerticalTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After connecting to the server"); + + // Create a window to draw into + + message("cscrollbarvertical_main: Create a Window\n"); + if (!test->createWindow()) + { + message("cscrollbarvertical_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After creating a window"); + + // Create a scrollbar + + message("cscrollbarvertical_main: Create a Scrollbar\n"); + CScrollbarVertical *scrollbar = test->createScrollbar(); + if (!scrollbar) + { + message("cscrollbarvertical_main: Failed to create a scrollbar\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After creating a scrollbar"); + + // Set the scrollbar minimum and maximum values + + scrollbar->setMinimumValue(0); + scrollbar->setMaximumValue(MAX_SCROLLBAR); + scrollbar->setValue(0); + message("cscrollbarvertical_main: Scrollbar range %d->%d Initial value %d\n", + scrollbar->getMinimumValue(), scrollbar->getMaximumValue(), + scrollbar->getValue()); + + // Show the initial state of the checkbox + + test->showScrollbar(scrollbar); + sleep(1); + + // Now move the scrollbar up + + for (int i = 0; i <= MAX_SCROLLBAR; i++) + { + scrollbar->setValue(i); + test->showScrollbar(scrollbar); + message("cscrollbarvertical_main: %d. New value %d\n", i, scrollbar->getValue()); + usleep(1000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After moving the scrollbar up"); + + // And move the scrollbar down + + for (int i = MAX_SCROLLBAR; i >= 0; i--) + { + scrollbar->setValue(i); + test->showScrollbar(scrollbar); + message("cscrollbarvertical_main: %d. New value %d\n", i, scrollbar->getValue()); + usleep(5000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After moving the scrollbar down"); + sleep(1); + + // Clean up and exit + + message("cscrollbarvertical_main: Clean-up and exit\n"); + delete scrollbar; + updateMemoryUsage(g_mmprevious, "After deleting the scrollbar"); + delete test; + updateMemoryUsage(g_mmprevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + return 0; +} + diff --git a/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx b/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx index e6005ced9..8b9fb1ee8 100644 --- a/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx +++ b/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx @@ -69,16 +69,6 @@ # define CONFIG_CSCROLLBARVERTICALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cscrollbarvertical_main -# define MAIN_STRING "cscrollbarvertical_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CScrollbarVertical/main.cxx b/NxWidgets/UnitTests/CScrollbarVertical/main.cxx deleted file mode 100644 index 16bd9eea6..000000000 --- a/NxWidgets/UnitTests/CScrollbarVertical/main.cxx +++ /dev/null @@ -1,231 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CScrollbarVertical/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "cscrollbarverticaltest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -#define MAX_SCROLLBAR 20 - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmprevious; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("\n%s:\n", msg); - message(" Before: %8d After: %8d Change: %8d\n\n", - previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the checkbox test - - message(MAIN_STRING "Create CScrollbarVerticalTest instance\n"); - CScrollbarVerticalTest *test = new CScrollbarVerticalTest(); - updateMemoryUsage(g_mmprevious, "After creating CScrollbarVerticalTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CScrollbarVerticalTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CScrollbarVerticalTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window"); - - // Create a scrollbar - - message(MAIN_STRING "Create a Scrollbar\n"); - CScrollbarVertical *scrollbar = test->createScrollbar(); - if (!scrollbar) - { - message(MAIN_STRING "Failed to create a scrollbar\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a scrollbar"); - - // Set the scrollbar minimum and maximum values - - scrollbar->setMinimumValue(0); - scrollbar->setMaximumValue(MAX_SCROLLBAR); - scrollbar->setValue(0); - message(MAIN_STRING "Scrollbar range %d->%d Initial value %d\n", - scrollbar->getMinimumValue(), scrollbar->getMaximumValue(), - scrollbar->getValue()); - - // Show the initial state of the checkbox - - test->showScrollbar(scrollbar); - sleep(1); - - // Now move the scrollbar up - - for (int i = 0; i <= MAX_SCROLLBAR; i++) - { - scrollbar->setValue(i); - test->showScrollbar(scrollbar); - message(MAIN_STRING "%d. New value %d\n", i, scrollbar->getValue()); - usleep(1000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the scrollbar up"); - - // And move the scrollbar down - - for (int i = MAX_SCROLLBAR; i >= 0; i--) - { - scrollbar->setValue(i); - test->showScrollbar(scrollbar); - message(MAIN_STRING "%d. New value %d\n", i, scrollbar->getValue()); - usleep(5000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the scrollbar down"); - sleep(1); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete scrollbar; - updateMemoryUsage(g_mmprevious, "After deleting the scrollbar"); - delete test; - updateMemoryUsage(g_mmprevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - return 0; -} - diff --git a/NxWidgets/UnitTests/CSliderHorizonal/Makefile b/NxWidgets/UnitTests/CSliderHorizonal/Makefile index 0a86aaf5f..0578510d3 100644 --- a/NxWidgets/UnitTests/CSliderHorizonal/Makefile +++ b/NxWidgets/UnitTests/CSliderHorizonal/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx csliderhorizontaltest.cxx +CXXSRCS = csliderhorizontal_main.cxx csliderhorizontaltest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontal_main.cxx b/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontal_main.cxx new file mode 100644 index 000000000..a336ba94a --- /dev/null +++ b/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontal_main.cxx @@ -0,0 +1,231 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CSliderHorizontal/csliderhorizontal_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "csliderhorizontaltest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +#define MAX_SLIDER 50 + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmprevious; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int csliderhorizontal_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("\n%s:\n", msg); + message(" Before: %8d After: %8d Change: %8d\n\n", + previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int csliderhorizontal_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the checkbox test + + message("csliderhorizontal_main: Create CSliderHorizontalTest instance\n"); + CSliderHorizontalTest *test = new CSliderHorizontalTest(); + updateMemoryUsage(g_mmprevious, "After creating CSliderHorizontalTest"); + + // Connect the NX server + + message("csliderhorizontal_main: Connect the CSliderHorizontalTest instance to the NX server\n"); + if (!test->connect()) + { + message("csliderhorizontal_main: Failed to connect the CSliderHorizontalTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After connecting to the server"); + + // Create a window to draw into + + message("csliderhorizontal_main: Create a Window\n"); + if (!test->createWindow()) + { + message("csliderhorizontal_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After creating a window"); + + // Create a slider + + message("csliderhorizontal_main: Create a Slider\n"); + CSliderHorizontal *slider = test->createSlider(); + if (!slider) + { + message("csliderhorizontal_main: Failed to create a slider\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After creating a slider"); + + // Set the slider minimum and maximum values + + slider->setMinimumValue(0); + slider->setMaximumValue(MAX_SLIDER); + slider->setValue(0); + message("csliderhorizontal_main: Slider range %d->%d Initial value %d\n", + slider->getMinimumValue(), slider->getMaximumValue(), + slider->getValue()); + + // Show the initial state of the checkbox + + test->showSlider(slider); + sleep(1); + + // Now move the slider up + + for (int i = 0; i <= MAX_SLIDER; i++) + { + slider->setValue(i); + test->showSlider(slider); + message("csliderhorizontal_main: %d. New value %d\n", i, slider->getValue()); + usleep(1000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After moving the slider up"); + + // And move the slider down + + for (int i = MAX_SLIDER; i >= 0; i--) + { + slider->setValue(i); + test->showSlider(slider); + message("csliderhorizontal_main: %d. New value %d\n", i, slider->getValue()); + usleep(1000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After moving the slider down"); + sleep(1); + + // Clean up and exit + + message("csliderhorizontal_main: Clean-up and exit\n"); + delete slider; + updateMemoryUsage(g_mmprevious, "After deleting the slider"); + delete test; + updateMemoryUsage(g_mmprevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + return 0; +} + diff --git a/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx b/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx index 99d6f739e..9709a2b7c 100644 --- a/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx +++ b/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx @@ -69,16 +69,6 @@ # define CONFIG_CSLIDERHORIZONTALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME csliderhorizontal_main -# define MAIN_STRING "csliderhorizontal_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CSliderHorizonal/main.cxx b/NxWidgets/UnitTests/CSliderHorizonal/main.cxx deleted file mode 100644 index b99d1c547..000000000 --- a/NxWidgets/UnitTests/CSliderHorizonal/main.cxx +++ /dev/null @@ -1,231 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CSliderHorizontal/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "csliderhorizontaltest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -#define MAX_SLIDER 50 - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmprevious; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("\n%s:\n", msg); - message(" Before: %8d After: %8d Change: %8d\n\n", - previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the checkbox test - - message(MAIN_STRING "Create CSliderHorizontalTest instance\n"); - CSliderHorizontalTest *test = new CSliderHorizontalTest(); - updateMemoryUsage(g_mmprevious, "After creating CSliderHorizontalTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CSliderHorizontalTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CSliderHorizontalTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window"); - - // Create a slider - - message(MAIN_STRING "Create a Slider\n"); - CSliderHorizontal *slider = test->createSlider(); - if (!slider) - { - message(MAIN_STRING "Failed to create a slider\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a slider"); - - // Set the slider minimum and maximum values - - slider->setMinimumValue(0); - slider->setMaximumValue(MAX_SLIDER); - slider->setValue(0); - message(MAIN_STRING "Slider range %d->%d Initial value %d\n", - slider->getMinimumValue(), slider->getMaximumValue(), - slider->getValue()); - - // Show the initial state of the checkbox - - test->showSlider(slider); - sleep(1); - - // Now move the slider up - - for (int i = 0; i <= MAX_SLIDER; i++) - { - slider->setValue(i); - test->showSlider(slider); - message(MAIN_STRING "%d. New value %d\n", i, slider->getValue()); - usleep(1000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the slider up"); - - // And move the slider down - - for (int i = MAX_SLIDER; i >= 0; i--) - { - slider->setValue(i); - test->showSlider(slider); - message(MAIN_STRING "%d. New value %d\n", i, slider->getValue()); - usleep(1000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the slider down"); - sleep(1); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete slider; - updateMemoryUsage(g_mmprevious, "After deleting the slider"); - delete test; - updateMemoryUsage(g_mmprevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - return 0; -} - diff --git a/NxWidgets/UnitTests/CSliderVertical/Makefile b/NxWidgets/UnitTests/CSliderVertical/Makefile index 76fd0da57..f37cc8619 100644 --- a/NxWidgets/UnitTests/CSliderVertical/Makefile +++ b/NxWidgets/UnitTests/CSliderVertical/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx csliderverticaltest.cxx +CXXSRCS = cslidervertical_main.cxx csliderverticaltest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx b/NxWidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx new file mode 100644 index 000000000..df356718b --- /dev/null +++ b/NxWidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx @@ -0,0 +1,231 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CSliderVertical/cslidervertical_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "csliderverticaltest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +#define MAX_SLIDER 50 + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static unsigned int g_mmInitial; +static unsigned int g_mmprevious; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int cslidervertical_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Private Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void updateMemoryUsage(unsigned int previous, + FAR const char *msg) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + + message("\n%s:\n", msg); + message(" Before: %8d After: %8d Change: %8d\n\n", + previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); + + /* Set up for the next test */ + + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_mmInitial = mmcurrent.uordblks; + g_mmprevious = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int cslidervertical_main(int argc, char *argv[]) +{ + // Initialize memory monitor logic + + initMemoryUsage(); + + // Create an instance of the checkbox test + + message("cslidervertical_main: Create CSliderVerticalTest instance\n"); + CSliderVerticalTest *test = new CSliderVerticalTest(); + updateMemoryUsage(g_mmprevious, "After creating CSliderVerticalTest"); + + // Connect the NX server + + message("cslidervertical_main: Connect the CSliderVerticalTest instance to the NX server\n"); + if (!test->connect()) + { + message("cslidervertical_main: Failed to connect the CSliderVerticalTest instance to the NX server\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cslidervertical_main: After connecting to the server"); + + // Create a window to draw into + + message("cslidervertical_main: Create a Window\n"); + if (!test->createWindow()) + { + message("cslidervertical_main: Failed to create a window\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cslidervertical_main: After creating a window"); + + // Create a slider + + message("cslidervertical_main: Create a Slider\n"); + CSliderVertical *slider = test->createSlider(); + if (!slider) + { + message("cslidervertical_main: Failed to create a slider\n"); + delete test; + return 1; + } + updateMemoryUsage(g_mmprevious, "cslidervertical_main: After creating a slider"); + + // Set the slider minimum and maximum values + + slider->setMinimumValue(0); + slider->setMaximumValue(MAX_SLIDER); + slider->setValue(0); + message("cslidervertical_main: Slider range %d->%d Initial value %d\n", + slider->getMinimumValue(), slider->getMaximumValue(), + slider->getValue()); + + // Show the initial state of the checkbox + + test->showSlider(slider); + sleep(1); + + // Now move the slider up + + for (int i = 0; i <= MAX_SLIDER; i++) + { + slider->setValue(i); + test->showSlider(slider); + message("cslidervertical_main: %d. New value %d\n", i, slider->getValue()); + usleep(1000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmprevious, "cslidervertical_main: After moving the slider up"); + + // And move the slider down + + for (int i = MAX_SLIDER; i >= 0; i--) + { + slider->setValue(i); + test->showSlider(slider); + message("cslidervertical_main: %d. New value %d\n", i, slider->getValue()); + usleep(1000); // The simulation needs this to let the X11 event loop run + } + updateMemoryUsage(g_mmprevious, "cslidervertical_main: After moving the slider down"); + sleep(1); + + // Clean up and exit + + message("cslidervertical_main: Clean-up and exit\n"); + delete slider; + updateMemoryUsage(g_mmprevious, "After deleting the slider"); + delete test; + updateMemoryUsage(g_mmprevious, "After deleting the test"); + updateMemoryUsage(g_mmInitial, "Final memory usage"); + return 0; +} + diff --git a/NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx b/NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx index a0d3df801..3bb174ba0 100644 --- a/NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx +++ b/NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx @@ -69,16 +69,6 @@ # define CONFIG_CSLIDERVERTICALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME cslidervertical_main -# define MAIN_STRING "cslidervertical_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - // If debug is enabled, use the debug function, lib_rawprintf() instead // of printf() so that the output is synchronized. diff --git a/NxWidgets/UnitTests/CSliderVertical/main.cxx b/NxWidgets/UnitTests/CSliderVertical/main.cxx deleted file mode 100644 index f5a53f018..000000000 --- a/NxWidgets/UnitTests/CSliderVertical/main.cxx +++ /dev/null @@ -1,231 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CSliderVertical/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "csliderverticaltest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -#define MAX_SLIDER 50 - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static unsigned int g_mmInitial; -static unsigned int g_mmprevious; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Private Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void updateMemoryUsage(unsigned int previous, - FAR const char *msg) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - - message("\n%s:\n", msg); - message(" Before: %8d After: %8d Change: %8d\n\n", - previous, mmcurrent.uordblks, mmcurrent.uordblks - previous); - - /* Set up for the next test */ - - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_mmInitial = mmcurrent.uordblks; - g_mmprevious = mmcurrent.uordblks; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Initialize memory monitor logic - - initMemoryUsage(); - - // Create an instance of the checkbox test - - message(MAIN_STRING "Create CSliderVerticalTest instance\n"); - CSliderVerticalTest *test = new CSliderVerticalTest(); - updateMemoryUsage(g_mmprevious, "After creating CSliderVerticalTest"); - - // Connect the NX server - - message(MAIN_STRING "Connect the CSliderVerticalTest instance to the NX server\n"); - if (!test->connect()) - { - message(MAIN_STRING "Failed to connect the CSliderVerticalTest instance to the NX server\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server"); - - // Create a window to draw into - - message(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - message(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window"); - - // Create a slider - - message(MAIN_STRING "Create a Slider\n"); - CSliderVertical *slider = test->createSlider(); - if (!slider) - { - message(MAIN_STRING "Failed to create a slider\n"); - delete test; - return 1; - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a slider"); - - // Set the slider minimum and maximum values - - slider->setMinimumValue(0); - slider->setMaximumValue(MAX_SLIDER); - slider->setValue(0); - message(MAIN_STRING "Slider range %d->%d Initial value %d\n", - slider->getMinimumValue(), slider->getMaximumValue(), - slider->getValue()); - - // Show the initial state of the checkbox - - test->showSlider(slider); - sleep(1); - - // Now move the slider up - - for (int i = 0; i <= MAX_SLIDER; i++) - { - slider->setValue(i); - test->showSlider(slider); - message(MAIN_STRING "%d. New value %d\n", i, slider->getValue()); - usleep(1000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the slider up"); - - // And move the slider down - - for (int i = MAX_SLIDER; i >= 0; i--) - { - slider->setValue(i); - test->showSlider(slider); - message(MAIN_STRING "%d. New value %d\n", i, slider->getValue()); - usleep(1000); // The simulation needs this to let the X11 event loop run - } - updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the slider down"); - sleep(1); - - // Clean up and exit - - message(MAIN_STRING "Clean-up and exit\n"); - delete slider; - updateMemoryUsage(g_mmprevious, "After deleting the slider"); - delete test; - updateMemoryUsage(g_mmprevious, "After deleting the test"); - updateMemoryUsage(g_mmInitial, "Final memory usage"); - return 0; -} - diff --git a/NxWidgets/UnitTests/CTextBox/Makefile b/NxWidgets/UnitTests/CTextBox/Makefile index bd7d98491..c368cc497 100644 --- a/NxWidgets/UnitTests/CTextBox/Makefile +++ b/NxWidgets/UnitTests/CTextBox/Makefile @@ -63,7 +63,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx ctextboxtest.cxx +CXXSRCS = ctextbox_main.cxx ctextboxtest.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/CTextBox/ctextbox_main.cxx b/NxWidgets/UnitTests/CTextBox/ctextbox_main.cxx new file mode 100644 index 000000000..da76c88cf --- /dev/null +++ b/NxWidgets/UnitTests/CTextBox/ctextbox_main.cxx @@ -0,0 +1,141 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/CTextBox/ctextbox_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include + +#include + +#include "ctextboxtest.hxx" + +///////////////////////////////////////////////////////////////////////////// +// Definitions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Classes +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static const char string1[] = "Johhn "; +static const char string2[] = "\b\b\bn Doe\r"; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int ctextbox_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxheaders_main +///////////////////////////////////////////////////////////////////////////// + +int ctextbox_main(int argc, char *argv[]) +{ + // Create an instance of the font test + + printf("ctextbox_main: Create CTextBoxTest instance\n"); + CTextBoxTest *test = new CTextBoxTest(); + + // Connect the NX server + + printf("ctextbox_main: Connect the CTextBoxTest instance to the NX server\n"); + if (!test->connect()) + { + printf("ctextbox_main: Failed to connect the CTextBoxTest instance to the NX server\n"); + delete test; + return 1; + } + + // Create a window to draw into + + printf("ctextbox_main: Create a Window\n"); + if (!test->createWindow()) + { + printf("ctextbox_main: Failed to create a window\n"); + delete test; + return 1; + } + + // Create a CTextBox instance + + CTextBox *textbox = test->createTextBox(); + if (!textbox) + { + printf("ctextbox_main: Failed to create a text box\n"); + delete test; + return 1; + } + + // Show the text box + + test->showTextBox(textbox); + + // Wait a bit, then inject a string with a typo + + sleep(1); + test->injectChars(textbox, sizeof(string1), (FAR const uint8_t*)string1); + + // Now fix the string with backspaces and finish it correctly + + usleep(500*1000); + test->injectChars(textbox, sizeof(string2), (FAR const uint8_t*)string2); + + // Clean up and exit + + sleep(2); + printf("ctextbox_main: Clean-up and exit\n"); + delete textbox; + delete test; + return 0; +} + diff --git a/NxWidgets/UnitTests/CTextBox/ctextboxtest.hxx b/NxWidgets/UnitTests/CTextBox/ctextboxtest.hxx index 1d470a1a8..9da8ce09f 100644 --- a/NxWidgets/UnitTests/CTextBox/ctextboxtest.hxx +++ b/NxWidgets/UnitTests/CTextBox/ctextboxtest.hxx @@ -75,16 +75,6 @@ # define CONFIG_CTEXTBOXTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME ctextbox_main -# define MAIN_STRING "ctextbox_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - ///////////////////////////////////////////////////////////////////////////// // Public Classes ///////////////////////////////////////////////////////////////////////////// diff --git a/NxWidgets/UnitTests/CTextBox/main.cxx b/NxWidgets/UnitTests/CTextBox/main.cxx deleted file mode 100644 index b5b8ec4d5..000000000 --- a/NxWidgets/UnitTests/CTextBox/main.cxx +++ /dev/null @@ -1,141 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/CTextBox/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include - -#include - -#include "ctextboxtest.hxx" - -///////////////////////////////////////////////////////////////////////////// -// Definitions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Classes -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static const char string1[] = "Johhn "; -static const char string2[] = "\b\b\bn Doe\r"; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxheaders_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Create an instance of the font test - - printf(MAIN_STRING "Create CTextBoxTest instance\n"); - CTextBoxTest *test = new CTextBoxTest(); - - // Connect the NX server - - printf(MAIN_STRING "Connect the CTextBoxTest instance to the NX server\n"); - if (!test->connect()) - { - printf(MAIN_STRING "Failed to connect the CTextBoxTest instance to the NX server\n"); - delete test; - return 1; - } - - // Create a window to draw into - - printf(MAIN_STRING "Create a Window\n"); - if (!test->createWindow()) - { - printf(MAIN_STRING "Failed to create a window\n"); - delete test; - return 1; - } - - // Create a CTextBox instance - - CTextBox *textbox = test->createTextBox(); - if (!textbox) - { - printf(MAIN_STRING "Failed to create a text box\n"); - delete test; - return 1; - } - - // Show the text box - - test->showTextBox(textbox); - - // Wait a bit, then inject a string with a typo - - sleep(1); - test->injectChars(textbox, sizeof(string1), (FAR const uint8_t*)string1); - - // Now fix the string with backspaces and finish it correctly - - usleep(500*1000); - test->injectChars(textbox, sizeof(string2), (FAR const uint8_t*)string2); - - // Clean up and exit - - sleep(2); - printf(MAIN_STRING "Clean-up and exit\n"); - delete textbox; - delete test; - return 0; -} - diff --git a/NxWidgets/UnitTests/nxwm/Makefile b/NxWidgets/UnitTests/nxwm/Makefile index 9648ad807..11c670ece 100644 --- a/NxWidgets/UnitTests/nxwm/Makefile +++ b/NxWidgets/UnitTests/nxwm/Makefile @@ -77,7 +77,7 @@ ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh ASRCS = CSRCS = -CXXSRCS = main.cxx +CXXSRCS = nxwm_main.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/NxWidgets/UnitTests/nxwm/main.cxx b/NxWidgets/UnitTests/nxwm/main.cxx deleted file mode 100644 index f61252904..000000000 --- a/NxWidgets/UnitTests/nxwm/main.cxx +++ /dev/null @@ -1,744 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// NxWidgets/UnitTests/nxwm/main.cxx -// -// Copyright (C) 2012 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors -// me be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Included Files -///////////////////////////////////////////////////////////////////////////// - -#include -#include - -#include -#include -#include - -#include "ctaskbar.hxx" -#include "cstartwindow.hxx" -#include "cnxconsole.hxx" -#include "chexcalculator.hxx" - -#ifdef CONFIG_NXWM_TOUCHSCREEN -# include "ctouchscreen.hxx" -# include "ccalibration.hxx" -#endif - -#ifdef CONFIG_NXWM_KEYBOARD -# include "ckeyboard.hxx" -#endif - -///////////////////////////////////////////////////////////////////////////// -// Pre-processor Definitions -///////////////////////////////////////////////////////////////////////////// - -// What is the entry point called? - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME nxwm_main -# define MAIN_STRING "nxwm_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - -#ifdef CONFIG_HAVE_FILENAME -# define showTestStepMemory(msg) \ - _showTestStepMemory((FAR const char*)__FILE__, (int)__LINE__, msg) -#endif - -#ifdef CONFIG_NXWIDGET_MEMMONITOR -# ifdef CONFIG_HAVE_FILENAME -# define showTestCaseMemory(msg) \ - _showTestCaseMemory((FAR const char*)__FILE__, (int)__LINE__, msg) -# define showTestMemory(msg) \ - _showTestMemory((FAR const char*)__FILE__, (int)__LINE__, msg) -# endif -#else -# define initMemoryUsage() -# define showTestCaseMemory(msg) -# define showTestMemory(msg) -#endif - -///////////////////////////////////////////////////////////////////////////// -// Private Types -///////////////////////////////////////////////////////////////////////////// - -struct SNxWmTest -{ - NxWM::CTaskbar *taskbar; // The task bar - NxWM::CStartWindow *startwindow; // The start window -#ifdef CONFIG_NXWM_TOUCHSCREEN - NxWM::CTouchscreen *touchscreen; // The touchscreen - struct NxWM::SCalibrationData calibData; // Calibration data -#endif -#ifdef CONFIG_NXWIDGET_MEMMONITOR - unsigned int mmInitial; // Initial memory usage - unsigned int mmStep; // Memory Usage at beginning of test step - unsigned int mmSubStep; // Memory Usage at beginning of test sub-step -#endif -}; - -///////////////////////////////////////////////////////////////////////////// -// Private Data -///////////////////////////////////////////////////////////////////////////// - -static struct SNxWmTest g_nxwmtest; - -///////////////////////////////////////////////////////////////////////////// -// Public Function Prototypes -///////////////////////////////////////////////////////////////////////////// - -// Suppress name-mangling - -extern "C" int MAIN_NAME(int argc, char *argv[]); - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: updateMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -#ifdef CONFIG_NXWIDGET_MEMMONITOR -#ifdef CONFIG_HAVE_FILENAME -static void updateMemoryUsage(unsigned int *previous, - FAR const char *file, int line, - FAR const char *msg) -#else -static void updateMemoryUsage(unsigned int *previous, - FAR const char *msg) -#endif -{ - struct mallinfo mmcurrent; - - /* Get the current memory usage */ - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - /* Show the change from the previous time */ - -#ifdef CONFIG_HAVE_FILENAME - printf("File: %s Line: %d : %s\n", file, line, msg); -#else - printf("\n%s:\n", msg); -#endif - printf(" Before: %8u After: %8u Change: %8d\n", - *previous, mmcurrent.uordblks, (int)mmcurrent.uordblks - (int)*previous); - - /* Set up for the next test */ - - *previous = mmcurrent.uordblks; -} -#endif - -///////////////////////////////////////////////////////////////////////////// -// Name: showTestCaseMemory -///////////////////////////////////////////////////////////////////////////// - -#ifdef CONFIG_NXWIDGET_MEMMONITOR -#ifdef CONFIG_HAVE_FILENAME -static void _showTestCaseMemory(FAR const char *file, int line, FAR const char *msg) -{ - updateMemoryUsage(&g_nxwmtest.mmStep, file, line, msg); - g_nxwmtest.mmSubStep = g_nxwmtest.mmInitial; -} -#else -static void showTestCaseMemory(FAR const char *msg) -{ - updateMemoryUsage(&g_nxwmtest.mmStep, msg); - g_nxwmtest.mmSubStep = g_nxwmtest.mmInitial; -} -#endif -#endif - -///////////////////////////////////////////////////////////////////////////// -// Name: showTestMemory -///////////////////////////////////////////////////////////////////////////// - -#ifdef CONFIG_NXWIDGET_MEMMONITOR -#ifdef CONFIG_HAVE_FILENAME -static void _showTestMemory(FAR const char *file, int line, FAR const char *msg) -{ - updateMemoryUsage(&g_nxwmtest.mmInitial, file, line, msg); -} -#else -static void showTestMemory(FAR const char *msg) -{ - updateMemoryUsage(&g_nxwmtest.mmInitial, msg); -} -#endif -#endif - -///////////////////////////////////////////////////////////////////////////// -// Name: initMemoryUsage -///////////////////////////////////////////////////////////////////////////// - -#ifdef CONFIG_NXWIDGET_MEMMONITOR -static void initMemoryUsage(void) -{ - struct mallinfo mmcurrent; - -#ifdef CONFIG_CAN_PASS_STRUCTS - mmcurrent = mallinfo(); -#else - (void)mallinfo(&mmcurrent); -#endif - - g_nxwmtest.mmInitial = mmcurrent.uordblks; - g_nxwmtest.mmStep = mmcurrent.uordblks; - g_nxwmtest.mmSubStep = mmcurrent.uordblks; -} -#endif - -///////////////////////////////////////////////////////////////////////////// -// Name: cleanup -///////////////////////////////////////////////////////////////////////////// - -static void testCleanUpAndExit(int exitCode) -{ -#ifdef CONFIG_NXWM_TOUCHSCREEN - if (g_nxwmtest.touchscreen) - { - delete g_nxwmtest.touchscreen; - } -#endif - - // Delete the task bar then the start window. the order is important because - // we must bet all of the application references out of the task bar before - // deleting the start window. When the start window is deleted, it will - // also delete of of the resouces contained within the start window. - - if (g_nxwmtest.taskbar) - { - delete g_nxwmtest.taskbar; - } - - if (g_nxwmtest.startwindow) - { - delete g_nxwmtest.startwindow; - } - - // And exit - - exit(exitCode); -} - -///////////////////////////////////////////////////////////////////////////// -// Name: createTaskbar -///////////////////////////////////////////////////////////////////////////// - -static bool createTaskbar(void) -{ - // Create an instance of the Task Bar. - // - // The general sequence for initializing the task bar is: - // - // 1. Create the CTaskbar instance, - // 2. Call the CTaskbar::connect() method to connect to the NX server (CTaskbar - // inherits the connect method from CNxServer), - // 3. Call the CTaskbar::initWindowManager() method to initialize the task bar. - // 3. Call CTaskBar::startApplication repeatedly to add applications to the task bar - // 4. Call CTaskBar::startWindowManager to start the display with applications in place - - printf("createTaskbar: Create CTaskbar instance\n"); - g_nxwmtest.taskbar = new NxWM::CTaskbar(); - if (!g_nxwmtest.taskbar) - { - printf("createTaskbar: ERROR: Failed to instantiate CTaskbar\n"); - return false; - } - showTestCaseMemory("createTaskbar: After create taskbar"); - - // Connect to the NX server - - printf("createTaskbar: Connect CTaskbar instance to the NX server\n"); - if (!g_nxwmtest.taskbar->connect()) - { - printf("createTaskbar: ERROR: Failed to connect CTaskbar instance to the NX server\n"); - return false; - } - showTestCaseMemory("createTaskbar: After connecting to the server"); - - // Initialize the task bar - // - // Taskbar::initWindowManager() prepares the task bar to receive applications. - // CTaskBar::startWindowManager() brings the window manager up with those applications - // in place. - - printf("createTaskbar: Initialize CTaskbar instance\n"); - if (!g_nxwmtest.taskbar->initWindowManager()) - { - printf("createTaskbar: ERROR: Failed to intialize CTaskbar instance\n"); - return false; - } - - showTestCaseMemory("createTaskbar: After initializing window manager"); - return true; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: createStartWindow -///////////////////////////////////////////////////////////////////////////// - -static bool createStartWindow(void) -{ - // Create the start window. The start window is unique among applications - // because it has no factory. The general sequence for setting up the - // start window is: - // - // 1. Create and open a CApplicationWindow - // 2. Use the window to create the CStartWindow the start window application - // 2. Call Cstartwindow::addApplication numerous times to install applications - // in the start window. - // 3. Call CTaskBar::startApplication (initially minimized) to start the start - // window application. - // - // NOTE: that the start window should not have a stop button. - - NxWM::CApplicationWindow *window = g_nxwmtest.taskbar->openApplicationWindow(NxWM::CApplicationWindow::WINDOW_PERSISTENT); - if (!window) - { - printf("createStartWindow: ERROR: Failed to create CApplicationWindow\n"); - return false; - } - showTestCaseMemory("createStartWindow: After creating CApplicationWindow"); - - // Open the window (it is hot in here) - - if (!window->open()) - { - printf("createStartWindow: ERROR: Failed to open CApplicationWindow \n"); - delete window; - return false; - } - showTestCaseMemory("createStartWindow: After opening CApplicationWindow"); - - // Instantiate the application, providing the window to the application's - // constructor - - g_nxwmtest.startwindow = new NxWM::CStartWindow(g_nxwmtest.taskbar, window); - if (!g_nxwmtest.startwindow) - { - gdbg("ERROR: Failed to instantiate CStartWindow\n"); - delete window; - return false; - } - showTestCaseMemory("createStartWindow: After creating CStartWindow"); - - // Add the CStartWindow application to the task bar (minimized) - - printf("createStartWindow: Start the start window application\n"); - if (!g_nxwmtest.taskbar->startApplication(g_nxwmtest.startwindow, true)) - { - printf("createStartWindow: ERROR: Failed to start the start window application\n"); - return false; - } - showTestCaseMemory("createStartWindow: After starting the start window application"); - return true; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: startWindowManager -///////////////////////////////////////////////////////////////////////////// - -static bool startWindowManager(void) -{ - // Start the window manager - - printf("startWindowManager: Start the window manager\n"); - if (!g_nxwmtest.taskbar->startWindowManager()) - { - printf("startWindowManager: ERROR: Failed to start the window manager\n"); - return false; - } - - showTestCaseMemory("startWindowManager: After starting the window manager"); - return true; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: createTouchScreen -///////////////////////////////////////////////////////////////////////////// - -#ifdef CONFIG_NXWM_TOUCHSCREEN -static bool createTouchScreen(void) -{ - // Get the physical size of the display in pixels - - struct nxgl_size_s displaySize; - (void)g_nxwmtest.taskbar->getDisplaySize(displaySize); - - // Create the touchscreen device - - printf("createTouchScreen: Creating CTouchscreen\n"); - g_nxwmtest.touchscreen = new NxWM::CTouchscreen(g_nxwmtest.taskbar, &displaySize); - if (!g_nxwmtest.touchscreen) - { - printf("createTouchScreen: ERROR: Failed to create CTouchscreen\n"); - return false; - } - showTestCaseMemory("createTouchScreen: After creating CTouchscreen"); - - printf("createTouchScreen: Start touchscreen listener\n"); - if (!g_nxwmtest.touchscreen->start()) - { - printf("createTouchScreen: ERROR: Failed start the touchscreen listener\n"); - delete g_nxwmtest.touchscreen; - return false; - } - - showTestCaseMemory("createTouchScreen: After starting the touchscreen listener"); - return true; -} -#endif - -///////////////////////////////////////////////////////////////////////////// -// Name: createKeyboard -///////////////////////////////////////////////////////////////////////////// - -#ifdef CONFIG_NXWM_KEYBOARD -static bool createKeyboard(void) -{ - printf("createKeyboard: Creating CKeyboard\n"); - NxWM::CKeyboard *keyboard = new NxWM::CKeyboard(g_nxwmtest.taskbar); - if (!keyboard) - { - printf("createKeyboard: ERROR: Failed to create CKeyboard\n"); - return false; - } - showTestCaseMemory("createKeyboard After creating CKeyboard"); - - printf("createKeyboard: Start keyboard listener\n"); - if (!keyboard->start()) - { - printf("createKeyboard: ERROR: Failed start the keyboard listener\n"); - delete keyboard; - return false; - } - - showTestCaseMemory("createKeyboard: After starting the keyboard listener"); - return true; -} -#endif - -///////////////////////////////////////////////////////////////////////////// -// Name: createCalibration -///////////////////////////////////////////////////////////////////////////// - -#ifdef CONFIG_NXWM_TOUCHSCREEN -static bool createCalibration(void) -{ - // 1Create the CCalibrationFactory application factory - - printf("createCalibration: Creating CCalibrationFactory\n"); - NxWM::CCalibrationFactory *factory = new NxWM::CCalibrationFactory(g_nxwmtest.taskbar, g_nxwmtest.touchscreen); - if (!factory) - { - printf("createCalibration: ERROR: Failed to create CCalibrationFactory\n"); - return false; - } - showTestCaseMemory("createCalibration: After creating CCalibrationFactory"); - - // Add the calibration application to the start window. - - printf("createCalibration: Adding CCalibration to the start window\n"); - if (!g_nxwmtest.startwindow->addApplication(factory)) - { - printf("createCalibration: ERROR: Failed to add CCalibrationto the start window\n"); - delete factory; - return false; - } - showTestCaseMemory("createCalibration: After adding CCalibration"); - - // Call StartWindowFactory::create to to create the start window application - - printf("createCalibration: Creating CCalibration\n"); - NxWM::IApplication *calibration = factory->create(); - if (!calibration) - { - printf("createCalibration: ERROR: Failed to create CCalibration\n"); - return false; - } - showTestCaseMemory("createCalibration: After creating CCalibration"); - - // Call CTaskBar::startApplication to start the Calibration application. Nothing - // will be displayed because the window manager has not yet been started. - - printf("createCalibration: Start the calibration application\n"); - if (!g_nxwmtest.taskbar->startApplication(calibration, false)) - { - printf(MAIN_STRING "ERROR: Failed to start the calibration application\n"); - delete calibration; - return false; - } - showTestCaseMemory("createCalibration: After starting the start window application"); - return true; -} -#endif - -///////////////////////////////////////////////////////////////////////////// -// Name: createNxConsole -///////////////////////////////////////////////////////////////////////////// - -static bool createNxConsole(void) -{ - // Add the NxConsole application to the start window - - printf("createNxConsole: Creating the NxConsole application\n"); - NxWM::CNxConsoleFactory *console = new NxWM::CNxConsoleFactory(g_nxwmtest.taskbar); - if (!console) - { - printf("createNxConsole: ERROR: Failed to instantiate CNxConsoleFactory\n"); - return false; - } - showTestCaseMemory("createNxConsole: After creating the NxConsole application"); - - printf("createNxConsole: Adding the NxConsole application to the start window\n"); - if (!g_nxwmtest.startwindow->addApplication(console)) - { - printf("createNxConsole: ERROR: Failed to add CNxConsoleFactory to the start window\n"); - delete console; - return false; - } - - showTestCaseMemory("createNxConsole: After adding the NxConsole application"); - return true; -} - -///////////////////////////////////////////////////////////////////////////// -// Name: createHexCalculator -///////////////////////////////////////////////////////////////////////////// - -static bool createHexCalculator(void) -{ - // Add the hex calculator application to the start window - - printf("createHexCalculator: Creating the hex calculator application\n"); - NxWM::CHexCalculatorFactory *calculator = new NxWM::CHexCalculatorFactory(g_nxwmtest.taskbar); - if (!calculator) - { - printf("createHexCalculator: ERROR: Failed to instantiate CHexCalculatorFactory\n"); - return false; - } - showTestCaseMemory("createHexCalculator: After creating the hex calculator application"); - - printf("createHexCalculator: Adding the hex calculator application to the start window\n"); - if (!g_nxwmtest.startwindow->addApplication(calculator)) - { - printf("createHexCalculator: ERROR: Failed to add CNxConsoleFactory to the start window\n"); - delete calculator; - return false; - } - - showTestCaseMemory("createHexCalculator: After adding the hex calculator application"); - return true; -} - -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// Name: showTestStepMemory -///////////////////////////////////////////////////////////////////////////// -// Called by ad hoc instrumentation in the NxWM/NxWidgets code - -#ifdef CONFIG_HAVE_FILENAME -void _showTestStepMemory(FAR const char *file, int line, FAR const char *msg) -{ -#ifdef CONFIG_NXWIDGET_MEMMONITOR - updateMemoryUsage(&g_nxwmtest.mmSubStep, file, line, msg); -#endif -} -#else -void showTestStepMemory(FAR const char *msg) -{ -#ifdef CONFIG_NXWIDGET_MEMMONITOR - updateMemoryUsage(&g_nxwmtest.mmSubStep, msg); -#endif -} -#endif - -///////////////////////////////////////////////////////////////////////////// -// user_start/nxwm_main -///////////////////////////////////////////////////////////////////////////// - -int MAIN_NAME(int argc, char *argv[]) -{ - // Call all C++ static constructors - -#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) - up_cxxinitialize(); -#endif - - // Initialize memory monitor logic - - initMemoryUsage(); - - // Initialize the NSH library - - printf(MAIN_STRING "Initialize the NSH library\n"); - if (!NxWM::nshlibInitialize()) - { - printf(MAIN_STRING "ERROR: Failed to initialize the NSH library\n"); - return EXIT_FAILURE; - } - showTestCaseMemory(MAIN_STRING "After initializing the NSH library"); - - // Create the task bar. - - if (!createTaskbar()) - { - printf(MAIN_STRING "ERROR: Failed to create the task bar\n"); - testCleanUpAndExit(EXIT_FAILURE); - } - - // Create the start window. - - if (!createStartWindow()) - { - printf(MAIN_STRING "ERROR: Failed to create the start window\n"); - testCleanUpAndExit(EXIT_FAILURE); - } - - // Create the keyboard device - -#ifdef CONFIG_NXWM_KEYBOARD - if (!createKeyboard()) - { - printf(MAIN_STRING "ERROR: Failed to create the keyboard\n"); - testCleanUpAndExit(EXIT_FAILURE); - } -#endif - - // Create the touchscreen device - -#ifdef CONFIG_NXWM_TOUCHSCREEN - if (!createTouchScreen()) - { - printf(MAIN_STRING "ERROR: Failed to create the touchscreen\n"); - testCleanUpAndExit(EXIT_FAILURE); - } -#endif - - // Create the calibration application and add it to the start window - -#ifdef CONFIG_NXWM_TOUCHSCREEN - if (!createCalibration()) - { - printf(MAIN_STRING "ERROR: Failed to create the calibration application\n"); - testCleanUpAndExit(EXIT_FAILURE); - } -#endif - - // Create the NxConsole application and add it to the start window - - if (!createNxConsole()) - { - printf(MAIN_STRING "ERROR: Failed to create the NxConsole application\n"); - testCleanUpAndExit(EXIT_FAILURE); - } - - // Create the hex calculator application and add it to the start window - - if (!createHexCalculator()) - { - printf(MAIN_STRING "ERROR: Failed to create the hex calculator application\n"); - testCleanUpAndExit(EXIT_FAILURE); - } - - // Call CTaskBar::startWindowManager to start the display with applications in place. - - if (!startWindowManager()) - { - printf(MAIN_STRING "ERROR: Failed to start the window manager\n"); - testCleanUpAndExit(EXIT_FAILURE); - } - -#ifdef CONFIG_NXWM_TOUCHSCREEN - // Since we started the touchscreen calibration program maximized, it will run - // immediately when we start the window manager. There is no positive handshake - // to know whenthe touchscreen has been calibrated. If we really want to know, - // we have to poll - - printf(MAIN_STRING "Waiting for touchscreen calibration\n"); - while (!g_nxwmtest.touchscreen->isCalibrated()) - { - std::sleep(2); - } - - // This is how we would then recover the calibration data. After the calibration - // application creates the calibration data, it hands it to the touchscreen driver - // After the touchscreen driver gets it, it will report isCalibrated() == true - // and then we can read the calibration data from the touchscreen driver. - - printf(MAIN_STRING "Getting calibration data from the touchscreen\n"); - if (!g_nxwmtest.touchscreen->getCalibrationData(g_nxwmtest.calibData)) - { - printf(MAIN_STRING "ERROR: Failed to get calibration data from the touchscreen\n"); - } -#endif - - // Wait a little bit for the display to stabilize. Then simulate pressing of - // the 'start window' icon in the task bar - -#ifndef CONFIG_NXWM_TOUCHSCREEN - sleep(2); - g_nxwmtest.taskbar->clickIcon(0, true); - usleep(500*1000); - g_nxwmtest.taskbar->clickIcon(0, false); - showTestCaseMemory(MAIN_STRING "After clicking the start window icon"); - - // Wait bit to see the result of the button press. Then press the first icon - // in the start menu. That should be the NxConsole icon. - - sleep(2); - g_nxwmtest.startwindow->clickIcon(0, true); - usleep(500*1000); - g_nxwmtest.startwindow->clickIcon(0, false); - showTestCaseMemory(MAIN_STRING "After clicking the NxConsole icon"); -#endif - - // Wait bit to see the result of the button press. - - sleep(2); - showTestMemory(MAIN_STRING "Final memory usage"); - return EXIT_SUCCESS; -} - diff --git a/NxWidgets/UnitTests/nxwm/nxwm_main.cxx b/NxWidgets/UnitTests/nxwm/nxwm_main.cxx new file mode 100644 index 000000000..eefc44494 --- /dev/null +++ b/NxWidgets/UnitTests/nxwm/nxwm_main.cxx @@ -0,0 +1,734 @@ +///////////////////////////////////////////////////////////////////////////// +// NxWidgets/UnitTests/nxwm/nxwm_main.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors +// me be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Included Files +///////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include +#include +#include + +#include "ctaskbar.hxx" +#include "cstartwindow.hxx" +#include "cnxconsole.hxx" +#include "chexcalculator.hxx" + +#ifdef CONFIG_NXWM_TOUCHSCREEN +# include "ctouchscreen.hxx" +# include "ccalibration.hxx" +#endif + +#ifdef CONFIG_NXWM_KEYBOARD +# include "ckeyboard.hxx" +#endif + +///////////////////////////////////////////////////////////////////////////// +// Pre-processor Definitions +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_HAVE_FILENAME +# define showTestStepMemory(msg) \ + _showTestStepMemory((FAR const char*)__FILE__, (int)__LINE__, msg) +#endif + +#ifdef CONFIG_NXWIDGET_MEMMONITOR +# ifdef CONFIG_HAVE_FILENAME +# define showTestCaseMemory(msg) \ + _showTestCaseMemory((FAR const char*)__FILE__, (int)__LINE__, msg) +# define showTestMemory(msg) \ + _showTestMemory((FAR const char*)__FILE__, (int)__LINE__, msg) +# endif +#else +# define initMemoryUsage() +# define showTestCaseMemory(msg) +# define showTestMemory(msg) +#endif + +///////////////////////////////////////////////////////////////////////////// +// Private Types +///////////////////////////////////////////////////////////////////////////// + +struct SNxWmTest +{ + NxWM::CTaskbar *taskbar; // The task bar + NxWM::CStartWindow *startwindow; // The start window +#ifdef CONFIG_NXWM_TOUCHSCREEN + NxWM::CTouchscreen *touchscreen; // The touchscreen + struct NxWM::SCalibrationData calibData; // Calibration data +#endif +#ifdef CONFIG_NXWIDGET_MEMMONITOR + unsigned int mmInitial; // Initial memory usage + unsigned int mmStep; // Memory Usage at beginning of test step + unsigned int mmSubStep; // Memory Usage at beginning of test sub-step +#endif +}; + +///////////////////////////////////////////////////////////////////////////// +// Private Data +///////////////////////////////////////////////////////////////////////////// + +static struct SNxWmTest g_nxwmtest; + +///////////////////////////////////////////////////////////////////////////// +// Public Function Prototypes +///////////////////////////////////////////////////////////////////////////// + +// Suppress name-mangling + +extern "C" int nxwm_main(int argc, char *argv[]); + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_NXWIDGET_MEMMONITOR +#ifdef CONFIG_HAVE_FILENAME +static void updateMemoryUsage(unsigned int *previous, + FAR const char *file, int line, + FAR const char *msg) +#else +static void updateMemoryUsage(unsigned int *previous, + FAR const char *msg) +#endif +{ + struct mallinfo mmcurrent; + + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + /* Show the change from the previous time */ + +#ifdef CONFIG_HAVE_FILENAME + printf("File: %s Line: %d : %s\n", file, line, msg); +#else + printf("\n%s:\n", msg); +#endif + printf(" Before: %8u After: %8u Change: %8d\n", + *previous, mmcurrent.uordblks, (int)mmcurrent.uordblks - (int)*previous); + + /* Set up for the next test */ + + *previous = mmcurrent.uordblks; +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: showTestCaseMemory +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_NXWIDGET_MEMMONITOR +#ifdef CONFIG_HAVE_FILENAME +static void _showTestCaseMemory(FAR const char *file, int line, FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmStep, file, line, msg); + g_nxwmtest.mmSubStep = g_nxwmtest.mmInitial; +} +#else +static void showTestCaseMemory(FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmStep, msg); + g_nxwmtest.mmSubStep = g_nxwmtest.mmInitial; +} +#endif +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: showTestMemory +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_NXWIDGET_MEMMONITOR +#ifdef CONFIG_HAVE_FILENAME +static void _showTestMemory(FAR const char *file, int line, FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmInitial, file, line, msg); +} +#else +static void showTestMemory(FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmInitial, msg); +} +#endif +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_NXWIDGET_MEMMONITOR +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_nxwmtest.mmInitial = mmcurrent.uordblks; + g_nxwmtest.mmStep = mmcurrent.uordblks; + g_nxwmtest.mmSubStep = mmcurrent.uordblks; +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: cleanup +///////////////////////////////////////////////////////////////////////////// + +static void testCleanUpAndExit(int exitCode) +{ +#ifdef CONFIG_NXWM_TOUCHSCREEN + if (g_nxwmtest.touchscreen) + { + delete g_nxwmtest.touchscreen; + } +#endif + + // Delete the task bar then the start window. the order is important because + // we must bet all of the application references out of the task bar before + // deleting the start window. When the start window is deleted, it will + // also delete of of the resouces contained within the start window. + + if (g_nxwmtest.taskbar) + { + delete g_nxwmtest.taskbar; + } + + if (g_nxwmtest.startwindow) + { + delete g_nxwmtest.startwindow; + } + + // And exit + + exit(exitCode); +} + +///////////////////////////////////////////////////////////////////////////// +// Name: createTaskbar +///////////////////////////////////////////////////////////////////////////// + +static bool createTaskbar(void) +{ + // Create an instance of the Task Bar. + // + // The general sequence for initializing the task bar is: + // + // 1. Create the CTaskbar instance, + // 2. Call the CTaskbar::connect() method to connect to the NX server (CTaskbar + // inherits the connect method from CNxServer), + // 3. Call the CTaskbar::initWindowManager() method to initialize the task bar. + // 3. Call CTaskBar::startApplication repeatedly to add applications to the task bar + // 4. Call CTaskBar::startWindowManager to start the display with applications in place + + printf("createTaskbar: Create CTaskbar instance\n"); + g_nxwmtest.taskbar = new NxWM::CTaskbar(); + if (!g_nxwmtest.taskbar) + { + printf("createTaskbar: ERROR: Failed to instantiate CTaskbar\n"); + return false; + } + showTestCaseMemory("createTaskbar: After create taskbar"); + + // Connect to the NX server + + printf("createTaskbar: Connect CTaskbar instance to the NX server\n"); + if (!g_nxwmtest.taskbar->connect()) + { + printf("createTaskbar: ERROR: Failed to connect CTaskbar instance to the NX server\n"); + return false; + } + showTestCaseMemory("createTaskbar: After connecting to the server"); + + // Initialize the task bar + // + // Taskbar::initWindowManager() prepares the task bar to receive applications. + // CTaskBar::startWindowManager() brings the window manager up with those applications + // in place. + + printf("createTaskbar: Initialize CTaskbar instance\n"); + if (!g_nxwmtest.taskbar->initWindowManager()) + { + printf("createTaskbar: ERROR: Failed to intialize CTaskbar instance\n"); + return false; + } + + showTestCaseMemory("createTaskbar: After initializing window manager"); + return true; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: createStartWindow +///////////////////////////////////////////////////////////////////////////// + +static bool createStartWindow(void) +{ + // Create the start window. The start window is unique among applications + // because it has no factory. The general sequence for setting up the + // start window is: + // + // 1. Create and open a CApplicationWindow + // 2. Use the window to create the CStartWindow the start window application + // 2. Call Cstartwindow::addApplication numerous times to install applications + // in the start window. + // 3. Call CTaskBar::startApplication (initially minimized) to start the start + // window application. + // + // NOTE: that the start window should not have a stop button. + + NxWM::CApplicationWindow *window = g_nxwmtest.taskbar->openApplicationWindow(NxWM::CApplicationWindow::WINDOW_PERSISTENT); + if (!window) + { + printf("createStartWindow: ERROR: Failed to create CApplicationWindow\n"); + return false; + } + showTestCaseMemory("createStartWindow: After creating CApplicationWindow"); + + // Open the window (it is hot in here) + + if (!window->open()) + { + printf("createStartWindow: ERROR: Failed to open CApplicationWindow \n"); + delete window; + return false; + } + showTestCaseMemory("createStartWindow: After opening CApplicationWindow"); + + // Instantiate the application, providing the window to the application's + // constructor + + g_nxwmtest.startwindow = new NxWM::CStartWindow(g_nxwmtest.taskbar, window); + if (!g_nxwmtest.startwindow) + { + gdbg("ERROR: Failed to instantiate CStartWindow\n"); + delete window; + return false; + } + showTestCaseMemory("createStartWindow: After creating CStartWindow"); + + // Add the CStartWindow application to the task bar (minimized) + + printf("createStartWindow: Start the start window application\n"); + if (!g_nxwmtest.taskbar->startApplication(g_nxwmtest.startwindow, true)) + { + printf("createStartWindow: ERROR: Failed to start the start window application\n"); + return false; + } + showTestCaseMemory("createStartWindow: After starting the start window application"); + return true; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: startWindowManager +///////////////////////////////////////////////////////////////////////////// + +static bool startWindowManager(void) +{ + // Start the window manager + + printf("startWindowManager: Start the window manager\n"); + if (!g_nxwmtest.taskbar->startWindowManager()) + { + printf("startWindowManager: ERROR: Failed to start the window manager\n"); + return false; + } + + showTestCaseMemory("startWindowManager: After starting the window manager"); + return true; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: createTouchScreen +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_NXWM_TOUCHSCREEN +static bool createTouchScreen(void) +{ + // Get the physical size of the display in pixels + + struct nxgl_size_s displaySize; + (void)g_nxwmtest.taskbar->getDisplaySize(displaySize); + + // Create the touchscreen device + + printf("createTouchScreen: Creating CTouchscreen\n"); + g_nxwmtest.touchscreen = new NxWM::CTouchscreen(g_nxwmtest.taskbar, &displaySize); + if (!g_nxwmtest.touchscreen) + { + printf("createTouchScreen: ERROR: Failed to create CTouchscreen\n"); + return false; + } + showTestCaseMemory("createTouchScreen: After creating CTouchscreen"); + + printf("createTouchScreen: Start touchscreen listener\n"); + if (!g_nxwmtest.touchscreen->start()) + { + printf("createTouchScreen: ERROR: Failed start the touchscreen listener\n"); + delete g_nxwmtest.touchscreen; + return false; + } + + showTestCaseMemory("createTouchScreen: After starting the touchscreen listener"); + return true; +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: createKeyboard +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_NXWM_KEYBOARD +static bool createKeyboard(void) +{ + printf("createKeyboard: Creating CKeyboard\n"); + NxWM::CKeyboard *keyboard = new NxWM::CKeyboard(g_nxwmtest.taskbar); + if (!keyboard) + { + printf("createKeyboard: ERROR: Failed to create CKeyboard\n"); + return false; + } + showTestCaseMemory("createKeyboard After creating CKeyboard"); + + printf("createKeyboard: Start keyboard listener\n"); + if (!keyboard->start()) + { + printf("createKeyboard: ERROR: Failed start the keyboard listener\n"); + delete keyboard; + return false; + } + + showTestCaseMemory("createKeyboard: After starting the keyboard listener"); + return true; +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: createCalibration +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_NXWM_TOUCHSCREEN +static bool createCalibration(void) +{ + // 1Create the CCalibrationFactory application factory + + printf("createCalibration: Creating CCalibrationFactory\n"); + NxWM::CCalibrationFactory *factory = new NxWM::CCalibrationFactory(g_nxwmtest.taskbar, g_nxwmtest.touchscreen); + if (!factory) + { + printf("createCalibration: ERROR: Failed to create CCalibrationFactory\n"); + return false; + } + showTestCaseMemory("createCalibration: After creating CCalibrationFactory"); + + // Add the calibration application to the start window. + + printf("createCalibration: Adding CCalibration to the start window\n"); + if (!g_nxwmtest.startwindow->addApplication(factory)) + { + printf("createCalibration: ERROR: Failed to add CCalibrationto the start window\n"); + delete factory; + return false; + } + showTestCaseMemory("createCalibration: After adding CCalibration"); + + // Call StartWindowFactory::create to to create the start window application + + printf("createCalibration: Creating CCalibration\n"); + NxWM::IApplication *calibration = factory->create(); + if (!calibration) + { + printf("createCalibration: ERROR: Failed to create CCalibration\n"); + return false; + } + showTestCaseMemory("createCalibration: After creating CCalibration"); + + // Call CTaskBar::startApplication to start the Calibration application. Nothing + // will be displayed because the window manager has not yet been started. + + printf("createCalibration: Start the calibration application\n"); + if (!g_nxwmtest.taskbar->startApplication(calibration, false)) + { + printf("createCalibration ERROR: Failed to start the calibration application\n"); + delete calibration; + return false; + } + showTestCaseMemory("createCalibration: After starting the start window application"); + return true; +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: createNxConsole +///////////////////////////////////////////////////////////////////////////// + +static bool createNxConsole(void) +{ + // Add the NxConsole application to the start window + + printf("createNxConsole: Creating the NxConsole application\n"); + NxWM::CNxConsoleFactory *console = new NxWM::CNxConsoleFactory(g_nxwmtest.taskbar); + if (!console) + { + printf("createNxConsole: ERROR: Failed to instantiate CNxConsoleFactory\n"); + return false; + } + showTestCaseMemory("createNxConsole: After creating the NxConsole application"); + + printf("createNxConsole: Adding the NxConsole application to the start window\n"); + if (!g_nxwmtest.startwindow->addApplication(console)) + { + printf("createNxConsole: ERROR: Failed to add CNxConsoleFactory to the start window\n"); + delete console; + return false; + } + + showTestCaseMemory("createNxConsole: After adding the NxConsole application"); + return true; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: createHexCalculator +///////////////////////////////////////////////////////////////////////////// + +static bool createHexCalculator(void) +{ + // Add the hex calculator application to the start window + + printf("createHexCalculator: Creating the hex calculator application\n"); + NxWM::CHexCalculatorFactory *calculator = new NxWM::CHexCalculatorFactory(g_nxwmtest.taskbar); + if (!calculator) + { + printf("createHexCalculator: ERROR: Failed to instantiate CHexCalculatorFactory\n"); + return false; + } + showTestCaseMemory("createHexCalculator: After creating the hex calculator application"); + + printf("createHexCalculator: Adding the hex calculator application to the start window\n"); + if (!g_nxwmtest.startwindow->addApplication(calculator)) + { + printf("createHexCalculator: ERROR: Failed to add CNxConsoleFactory to the start window\n"); + delete calculator; + return false; + } + + showTestCaseMemory("createHexCalculator: After adding the hex calculator application"); + return true; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: showTestStepMemory +///////////////////////////////////////////////////////////////////////////// +// Called by ad hoc instrumentation in the NxWM/NxWidgets code + +#ifdef CONFIG_HAVE_FILENAME +void _showTestStepMemory(FAR const char *file, int line, FAR const char *msg) +{ +#ifdef CONFIG_NXWIDGET_MEMMONITOR + updateMemoryUsage(&g_nxwmtest.mmSubStep, file, line, msg); +#endif +} +#else +void showTestStepMemory(FAR const char *msg) +{ +#ifdef CONFIG_NXWIDGET_MEMMONITOR + updateMemoryUsage(&g_nxwmtest.mmSubStep, msg); +#endif +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxwm_main +///////////////////////////////////////////////////////////////////////////// + +int nxwm_main(int argc, char *argv[]) +{ + // Call all C++ static constructors + +#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) + up_cxxinitialize(); +#endif + + // Initialize memory monitor logic + + initMemoryUsage(); + + // Initialize the NSH library + + printf("nxwm_main: Initialize the NSH library\n"); + if (!NxWM::nshlibInitialize()) + { + printf("nxwm_main: ERROR: Failed to initialize the NSH library\n"); + return EXIT_FAILURE; + } + showTestCaseMemory("nxwm_main: After initializing the NSH library"); + + // Create the task bar. + + if (!createTaskbar()) + { + printf("nxwm_main: ERROR: Failed to create the task bar\n"); + testCleanUpAndExit(EXIT_FAILURE); + } + + // Create the start window. + + if (!createStartWindow()) + { + printf("nxwm_main: ERROR: Failed to create the start window\n"); + testCleanUpAndExit(EXIT_FAILURE); + } + + // Create the keyboard device + +#ifdef CONFIG_NXWM_KEYBOARD + if (!createKeyboard()) + { + printf("nxwm_main: ERROR: Failed to create the keyboard\n"); + testCleanUpAndExit(EXIT_FAILURE); + } +#endif + + // Create the touchscreen device + +#ifdef CONFIG_NXWM_TOUCHSCREEN + if (!createTouchScreen()) + { + printf("nxwm_main ERROR: Failed to create the touchscreen\n"); + testCleanUpAndExit(EXIT_FAILURE); + } +#endif + + // Create the calibration application and add it to the start window + +#ifdef CONFIG_NXWM_TOUCHSCREEN + if (!createCalibration()) + { + printf("nxwm_main ERROR: Failed to create the calibration application\n"); + testCleanUpAndExit(EXIT_FAILURE); + } +#endif + + // Create the NxConsole application and add it to the start window + + if (!createNxConsole()) + { + printf("nxwm_main: ERROR: Failed to create the NxConsole application\n"); + testCleanUpAndExit(EXIT_FAILURE); + } + + // Create the hex calculator application and add it to the start window + + if (!createHexCalculator()) + { + printf("nxwm_main: ERROR: Failed to create the hex calculator application\n"); + testCleanUpAndExit(EXIT_FAILURE); + } + + // Call CTaskBar::startWindowManager to start the display with applications in place. + + if (!startWindowManager()) + { + printf("nxwm_main: ERROR: Failed to start the window manager\n"); + testCleanUpAndExit(EXIT_FAILURE); + } + +#ifdef CONFIG_NXWM_TOUCHSCREEN + // Since we started the touchscreen calibration program maximized, it will run + // immediately when we start the window manager. There is no positive handshake + // to know whenthe touchscreen has been calibrated. If we really want to know, + // we have to poll + + printf("nxwm_main: Waiting for touchscreen calibration\n"); + while (!g_nxwmtest.touchscreen->isCalibrated()) + { + std::sleep(2); + } + + // This is how we would then recover the calibration data. After the calibration + // application creates the calibration data, it hands it to the touchscreen driver + // After the touchscreen driver gets it, it will report isCalibrated() == true + // and then we can read the calibration data from the touchscreen driver. + + printf("nxwm_main: Getting calibration data from the touchscreen\n"); + if (!g_nxwmtest.touchscreen->getCalibrationData(g_nxwmtest.calibData)) + { + printf("nxwm_main: ERROR: Failed to get calibration data from the touchscreen\n"); + } +#endif + + // Wait a little bit for the display to stabilize. Then simulate pressing of + // the 'start window' icon in the task bar + +#ifndef CONFIG_NXWM_TOUCHSCREEN + sleep(2); + g_nxwmtest.taskbar->clickIcon(0, true); + usleep(500*1000); + g_nxwmtest.taskbar->clickIcon(0, false); + showTestCaseMemory("nxwm_main: After clicking the start window icon"); + + // Wait bit to see the result of the button press. Then press the first icon + // in the start menu. That should be the NxConsole icon. + + sleep(2); + g_nxwmtest.startwindow->clickIcon(0, true); + usleep(500*1000); + g_nxwmtest.startwindow->clickIcon(0, false); + showTestCaseMemory("nxwm_main: After clicking the NxConsole icon"); +#endif + + // Wait bit to see the result of the button press. + + sleep(2); + showTestMemory("nxwm_main: Final memory usage"); + return EXIT_SUCCESS; +} + -- cgit v1.2.3