From 68f3044b5099572850a9e81a1c63161c20809547 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 10 May 2012 16:25:56 +0000 Subject: NX trapezoid fixes; Various NxWM fixes git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4720 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/UnitTests/nxwm/main.cxx | 363 +++++++++++++++++++++++--------------- 1 file changed, 218 insertions(+), 145 deletions(-) (limited to 'NxWidgets/UnitTests/nxwm') diff --git a/NxWidgets/UnitTests/nxwm/main.cxx b/NxWidgets/UnitTests/nxwm/main.cxx index e7a16727d..7cdc778e0 100644 --- a/NxWidgets/UnitTests/nxwm/main.cxx +++ b/NxWidgets/UnitTests/nxwm/main.cxx @@ -78,14 +78,16 @@ struct SNxWmTest { - NxWM::CTaskbar *taskbar; // The task bar - NxWM::CStartWindow *startwindow; // The start window + NxWM::CTaskbar *taskbar; // The task bar + NxWM::CStartWindow *startwindow; // The start window #ifdef CONFIG_NXWM_TOUCHSCREEN - NxWM::CTouchscreen *touchscreen; // The touchscreen + NxWM::CTouchscreen *touchscreen; // The touchscreen + NxWM::CCalibration *calibration; // The touchscreen calibration application + struct NxWM::SCalibrationData data; // Calibration data #endif - 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 + 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 }; ///////////////////////////////////////////////////////////////////////////// @@ -201,7 +203,7 @@ static void initMemoryUsage(void) // Name: cleanup ///////////////////////////////////////////////////////////////////////////// -static void test_cleanup(void) +static void testCleanUpAndExit(int exitCode) { #ifdef CONFIG_NXWM_TOUCHSCREEN if (g_nxwmtest.touchscreen) @@ -224,55 +226,18 @@ static void test_cleanup(void) { delete g_nxwmtest.startwindow; } -} -///////////////////////////////////////////////////////////////////////////// -// Public Functions -///////////////////////////////////////////////////////////////////////////// + // And exit -///////////////////////////////////////////////////////////////////////////// -// 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) -{ - updateMemoryUsage(&g_nxwmtest.mmSubStep, file, line, msg); + exit(exitCode); } -#else -void showTestStepMemory(FAR const char *msg) -{ - updateMemoryUsage(&g_nxwmtest.mmSubStep, msg); -} -#endif ///////////////////////////////////////////////////////////////////////////// -// user_start/nxwm_main +// Name: createTaskbar ///////////////////////////////////////////////////////////////////////////// -int MAIN_NAME(int argc, char *argv[]) +static bool createTaskbar(void) { - // 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("After initializing the NSH library"); - // Create an instance of the Task Bar. // // The general sequence for initializing the task bar is: @@ -289,7 +254,7 @@ int MAIN_NAME(int argc, char *argv[]) if (!g_nxwmtest.taskbar) { printf(MAIN_STRING "ERROR: Failed to instantiate CTaskbar\n"); - return EXIT_FAILURE; + return false; } showTestCaseMemory("After create taskbar"); @@ -299,8 +264,7 @@ int MAIN_NAME(int argc, char *argv[]) if (!g_nxwmtest.taskbar->connect()) { printf(MAIN_STRING "ERROR: Failed to connect the CTaskbar instance to the NX server\n"); - test_cleanup(); - return EXIT_FAILURE; + return false; } showTestCaseMemory("After connecting to the server"); @@ -314,11 +278,19 @@ int MAIN_NAME(int argc, char *argv[]) if (!g_nxwmtest.taskbar->initWindowManager()) { printf(MAIN_STRING "ERROR: Failed to intialize the CTaskbar instance\n"); - test_cleanup(); - return EXIT_FAILURE; + return false; } - showTestCaseMemory("After initializing window manager"); + showTestCaseMemory("After initializing window manager"); + return true; +} + +///////////////////////////////////////////////////////////////////////////// +// Name: createStartWindow +///////////////////////////////////////////////////////////////////////////// + +static bool createStartWindow(void) +{ // Create the start window. The general sequence for setting up the start window is: // // 1. Call CTaskBar::openApplicationWindow to create a window for the start window, @@ -333,8 +305,7 @@ int MAIN_NAME(int argc, char *argv[]) if (!window) { printf(MAIN_STRING "ERROR: Failed to create CApplicationWindow for the start window\n"); - test_cleanup(); - return EXIT_FAILURE; + return false; } showTestCaseMemory("After creating start window application window"); @@ -343,8 +314,7 @@ int MAIN_NAME(int argc, char *argv[]) { printf(MAIN_STRING "ERROR: Failed to open the CApplicationWindow \n"); delete window; - test_cleanup(); - return EXIT_FAILURE; + return false; } showTestCaseMemory("After initializing the start window application window"); @@ -354,30 +324,49 @@ int MAIN_NAME(int argc, char *argv[]) { printf(MAIN_STRING "ERROR: Failed to instantiate CStartWindow\n"); delete window; - test_cleanup(); - return EXIT_FAILURE; + return false; + } + + // Call CTaskBar::startApplication to start the Calibration application (minimized) + + printf(MAIN_STRING "Start the start window application\n"); + if (!g_nxwmtest.taskbar->startApplication(g_nxwmtest.startwindow, true)) + { + printf(MAIN_STRING "ERROR: Failed to start the start window application\n"); + return false; } + showTestCaseMemory("After starting the start window application"); + showTestCaseMemory("After create the start window application"); + return true; +} - // Perform touchscreen calibration +///////////////////////////////////////////////////////////////////////////// +// Name: startWindowManager +///////////////////////////////////////////////////////////////////////////// -#ifdef CONFIG_NXWM_TOUCHSCREEN - // Start the window manager before adding applications +static bool startWindowManager(void) +{ + // Start the window manager printf(MAIN_STRING "Start the window manager\n"); if (!g_nxwmtest.taskbar->startWindowManager()) { printf(MAIN_STRING "ERROR: Failed to start the window manager\n"); - test_cleanup(); - return EXIT_FAILURE; + return false; } - showTestCaseMemory("After starting the window manager"); - // Perform touchscreen calibration + showTestCaseMemory("After starting the window manager"); + return true; +} - NxWM::CCalibration *calibration = (NxWM::CCalibration *)0; // Avoid compiler complaint - NxWM::CFullScreenWindow *fullscreen = (NxWM::CFullScreenWindow *)0; // Avoid compiler complaint +///////////////////////////////////////////////////////////////////////////// +// Name: createTouchScreen +///////////////////////////////////////////////////////////////////////////// +#ifdef CONFIG_NXWM_TOUCHSCREEN +static bool createTouchScreen(void) +{ // Create the touchscreen device printf(MAIN_STRING "Creating CTouchscreen\n"); @@ -385,7 +374,7 @@ int MAIN_NAME(int argc, char *argv[]) if (!g_nxwmtest.touchscreen) { printf(MAIN_STRING "ERROR: Failed to create CTouchscreen\n"); - goto nocalibration; + return false; } printf(MAIN_STRING "Initialize the CTouchscreen\n"); @@ -393,10 +382,21 @@ int MAIN_NAME(int argc, char *argv[]) { printf(MAIN_STRING "ERROR: Failed to open the CTouchscreen \n"); delete g_nxwmtest.touchscreen; - goto nocalibration; + return false; } + showTestCaseMemory("After initializing CTouchscreen"); + return true; +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: createCalibration +///////////////////////////////////////////////////////////////////////////// +#ifdef CONFIG_NXWM_TOUCHSCREEN +static bool createCalibration(void) +{ // 1. Call CTaskBar::FullScreenWindow to create a window for the application, // 2. Instantiate the application, providing the window to the application's // constructor, @@ -405,75 +405,99 @@ int MAIN_NAME(int argc, char *argv[]) // 4. Call CTaskBar::startApplication start the application and bring its window to // the top. - printf(MAIN_STRING "Opening the calibrationapplication window\n"); - fullscreen = g_nxwmtest.taskbar->openFullScreenWindow(); - if (!fullscreen) + printf(MAIN_STRING "Opening the calibration application window\n"); + NxWM::CFullScreenWindow *window = g_nxwmtest.taskbar->openFullScreenWindow(); + if (!window) { printf(MAIN_STRING "ERROR: Failed to create CFullScreenWindow for the calibration window\n"); - goto nocalibration; + return false; } showTestCaseMemory("After creating calibration full screen window"); printf(MAIN_STRING "Initialize the CFullScreenWindow\n"); - if (!fullscreen->open()) + if (!window->open()) { printf(MAIN_STRING "ERROR: Failed to open the CFullScreenWindow \n"); - delete fullscreen; - goto nocalibration; + delete window; + return false; } showTestCaseMemory("After initializing the calibration full screen window"); printf(MAIN_STRING "Creating the CCalibration application\n"); - calibration = new NxWM::CCalibration(fullscreen, g_nxwmtest.touchscreen); - if (!calibration) + g_nxwmtest.calibration = new NxWM::CCalibration(window, g_nxwmtest.touchscreen); + if (!g_nxwmtest.calibration) { printf(MAIN_STRING "ERROR: Failed to instantiate CCalibration\n"); - delete fullscreen; - goto nocalibration; + delete window; + return false; } showTestCaseMemory("After creating the CCalibration application"); printf(MAIN_STRING "Adding the CCalibration application to the start window\n"); - if (!g_nxwmtest.startwindow->addApplication(calibration)) + if (!g_nxwmtest.startwindow->addApplication(g_nxwmtest.calibration)) { printf(MAIN_STRING "ERROR: Failed to add CCalibration to the start window\n"); - delete calibration; - goto nocalibration; + delete g_nxwmtest.calibration; + return false; } + showTestCaseMemory("After adding the CCalibration application"); + return true; +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: runCalibration +///////////////////////////////////////////////////////////////////////////// +#ifdef CONFIG_NXWM_TOUCHSCREEN +static bool runCalibration(void) +{ // Call CTaskBar::startApplication to start the Calibration application - printf(MAIN_STRING "Start the start window application\n"); - if (!g_nxwmtest.taskbar->startApplication(calibration, false)) + printf(MAIN_STRING "Start the calibration application\n"); + if (!g_nxwmtest.taskbar->startApplication(g_nxwmtest.calibration, false)) { printf(MAIN_STRING "ERROR: Failed to start the calibration application\n"); - goto nocalibration; + return false; } showTestCaseMemory("After starting the start window application"); // Wait for calibration data printf(MAIN_STRING "Get calibration data\n"); - struct NxWM::SCalibrationData data; - if (!calibration->waitCalibrationData(data)) + if (!g_nxwmtest.calibration->waitCalibrationData(g_nxwmtest.data)) { printf(MAIN_STRING "ERROR: Failed to get calibration data\n"); + return false; + } + + printf(MAIN_STRING "Stop the calibration application\n"); + if (!g_nxwmtest.taskbar->stopApplication(g_nxwmtest.calibration)) + { + printf(MAIN_STRING "ERROR: Failed to stop the calibration application\n"); + return false; } -nocalibration: + showTestCaseMemory("After stopping the calibration application"); + return true; +} #endif - // Add the NxConsole application to the start window +///////////////////////////////////////////////////////////////////////////// +// Name: createNxConsole +///////////////////////////////////////////////////////////////////////////// - NxWM::CNxConsole *console = (NxWM::CNxConsole *)0; // Avoid compiler complaint +static bool createNxConsole(void) +{ + // Add the NxConsole application to the start window printf(MAIN_STRING "Opening the NxConsole application window\n"); - window = g_nxwmtest.taskbar->openApplicationWindow(); + NxWM::CApplicationWindow *window = g_nxwmtest.taskbar->openApplicationWindow(); if (!window) { printf(MAIN_STRING "ERROR: Failed to create CApplicationWindow for the NxConsole\n"); - goto noconsole; + return false; } showTestCaseMemory("After creating the NxConsole application window"); @@ -482,17 +506,17 @@ nocalibration: { printf(MAIN_STRING "ERROR: Failed to open the CApplicationWindow \n"); delete window; - goto noconsole; + return false; } showTestCaseMemory("After initializing the NxConsole application window"); printf(MAIN_STRING "Creating the NxConsole application\n"); - console = new NxWM::CNxConsole(g_nxwmtest.taskbar, window); + NxWM::CNxConsole *console = new NxWM::CNxConsole(g_nxwmtest.taskbar, window); if (!console) { printf(MAIN_STRING "ERROR: Failed to instantiate CNxConsole\n"); delete window; - goto noconsole; + return false; } showTestCaseMemory("After creating the NxConsole application"); @@ -500,81 +524,130 @@ nocalibration: if (!g_nxwmtest.startwindow->addApplication(console)) { printf(MAIN_STRING "ERROR: Failed to add CNxConsole to the start window\n"); - delete window; + delete console; + return false; } + showTestCaseMemory("After adding the NxConsole 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) +{ + updateMemoryUsage(&g_nxwmtest.mmSubStep, file, line, msg); +} +#else +void showTestStepMemory(FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmSubStep, msg); +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// user_start/nxwm_main +///////////////////////////////////////////////////////////////////////////// -noconsole: +int MAIN_NAME(int argc, char *argv[]) +{ + // Call all C++ static constructors - // Add the calculator application to the start window +#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) + up_cxxinitialize(); +#endif -#if 0 - NxWM::CCalculator *calculator = (NxWM::CCalculator *)0; // Avoid compiler complaint + // Initialize memory monitor logic - printf(MAIN_STRING "Opening the calculator application window\n"); - window = g_nxwmtest.taskbar->openApplicationWindow(); - if (!window) + initMemoryUsage(); + + // Initialize the NSH library + + printf(MAIN_STRING "Initialize the NSH library\n"); + if (!NxWM::nshlibInitialize()) { - printf(MAIN_STRING "ERROR: Failed to create CApplicationWindow for the calculator\n"); - goto nocalculator; + printf(MAIN_STRING "ERROR: Failed to initialize the NSH library\n"); + return EXIT_FAILURE; } - showTestCaseMemory("After creating the calculator application window"); + showTestCaseMemory("After initializing the NSH library"); - printf(MAIN_STRING "Initialize the CApplicationWindow\n"); - if (!window->open()) + // Create the task bar. + + if (!createTaskbar()) { - printf(MAIN_STRING "ERROR: Failed to open the CApplicationWindow \n"); - delete window; - test_cleanup(); - return EXIT_FAILURE; + printf(MAIN_STRING "Failed to create the task bar\n"); + testCleanUpAndExit(EXIT_FAILURE); } - showTestCaseMemory("After creating the initializing application window"); - printf(MAIN_STRING "Creating the calculator application\n"); - calculator = new NxWM::CCalculator(g_nxwmtest.taskbar, window); - if (!calculator) + // Create the start window. + + if (!createStartWindow()) { - printf(MAIN_STRING "ERROR: Failed to instantiate calculator\n"); - delete window; - goto nocalculator; + printf(MAIN_STRING "Failed to create the start window\n"); + testCleanUpAndExit(EXIT_FAILURE); } - showTestCaseMemory("After creating the calculator application"); - printf(MAIN_STRING "Adding the calculator application to the start window\n"); - if (!g_nxwmtest.startwindow->addApplication(calculator)) + // Create the touchscreen device + +#ifdef CONFIG_NXWM_TOUCHSCREEN + if (!createTouchScreen()) { - printf(MAIN_STRING "ERROR: Failed to add calculator to the start window\n"); - delete window; + printf(MAIN_STRING "Failed to create the start window\n"); + testCleanUpAndExit(EXIT_FAILURE); + } +#endif + + // Perform touchscreen calibration + +#ifdef CONFIG_NXWM_TOUCHSCREEN + // Create the touchscreen device + + if (!createTouchScreen()) + { + printf(MAIN_STRING "Failed to create the touchscreen\n"); + testCleanUpAndExit(EXIT_FAILURE); + } + + // Create the calibration application + + if (!createCalibration()) + { + printf(MAIN_STRING "Failed to create the calibration application\n"); + testCleanUpAndExit(EXIT_FAILURE); } - showTestCaseMemory("After adding the calculator application"); -nocalculator: + // Run the touchscreen calibration application + + if (!runCalibration()) + { + printf(MAIN_STRING "Touchscreen Calibration failed\n"); + testCleanUpAndExit(EXIT_FAILURE); + } #endif - // Call CTaskBar::startApplication to start the start window application. The initial - // state of the start window is minimized. + // Add the NxConsole application to the start window - printf(MAIN_STRING "Start the start window application\n"); - if (!g_nxwmtest.taskbar->startApplication(g_nxwmtest.startwindow, true)) + if (!createNxConsole()) { - printf(MAIN_STRING "ERROR: Failed to start the start window application\n"); - test_cleanup(); - return EXIT_FAILURE; + printf(MAIN_STRING "Failed to create the NxConsole application\n"); + testCleanUpAndExit(EXIT_FAILURE); } - showTestCaseMemory("After starting the start window application"); // Call CTaskBar::startWindowManager to start the display with applications in place. -#ifndef CONFIG_NXWM_TOUCHSCREEN - printf(MAIN_STRING "Start the window manager\n"); - if (!g_nxwmtest.taskbar->startWindowManager()) + if (!startWindowManager()) { - printf(MAIN_STRING "ERROR: Failed to start the window manager\n"); - test_cleanup(); - return EXIT_FAILURE; + printf(MAIN_STRING "Failed to start the window manager\n"); + testCleanUpAndExit(EXIT_FAILURE); } - showTestCaseMemory("After starting the window manager"); -#endif // Wait a little bit for the display to stabilize. The simulation pressing of // the 'start window' icon in the task bar -- cgit v1.2.3