Back to index

nux  3.0.0
Classes | Functions | Variables
xtest-text-entry.cpp File Reference
#include "Nux/Nux.h"
#include "Nux/WindowThread.h"
#include "Nux/VLayout.h"
#include "Nux/TextEntry.h"
#include "Nux/InputMethodIBus.h"
#include "Nux/ProgramFramework/ProgramTemplate.h"
#include "Nux/ProgramFramework/TestView.h"
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include "nux_automated_test_framework.h"

Go to the source code of this file.

Classes

class  TextTextEntry

Functions

bool SetEngineActive (IBusBus *bus_, std::string engine)
void TestingThread (nux::NThread *thread, void *user_data)
int main (int argc, char **argv)

Variables

TextTextEntrytest_textentry = NULL

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 454 of file xtest-text-entry.cpp.

{
  int xstatus = XInitThreads();
  nuxAssertMsg(xstatus > 0, "XInitThreads has failed");

  test_textentry = new TextTextEntry("Text Entry", 600, 200, 40000);
  test_textentry->Startup();
  test_textentry->UserInterfaceSetup();

  nux::SystemThread* test_thread = nux::CreateSystemThread(NULL, &TestingThread, test_textentry->GetWindowThread());

  test_thread->Start(test_textentry);

  test_textentry->Run();

  delete test_thread;
  delete test_textentry;

  return 0;
}

Here is the call graph for this function:

bool SetEngineActive ( IBusBus *  bus_,
std::string  engine 
)

Definition at line 113 of file xtest-text-entry.cpp.

{
    GList* engines = ibus_bus_list_active_engines(bus_);
    if (!engines)
      return false;

    GList* start = engines;
    bool found = false;
    gboolean global_flag = ibus_bus_get_use_global_engine(bus_);

    // Iterates through the active engines
    do
    {
      IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (engines->data);

      // Found Engine, make it active!
      if (engine == ibus_engine_desc_get_name(engine_desc))
      {
        found = true;

        // Set ibus to use global engines
        if (!global_flag)
          ibus_config_set_value(ibus_bus_get_config(bus_),
                                "general",
                                "use_global_engine",
                                g_variant_new_boolean(true));

        // Set and activate the engine
        ibus_bus_set_global_engine(bus_, engine.c_str());
      }
    } while ((engines = g_list_next(engines)) != NULL);

    // Restores the global setting back to what it was
    ibus_config_set_value(ibus_bus_get_config(bus_),
                          "general",
                          "use_global_engine",
                          g_variant_new_boolean(global_flag));

    g_list_free(start);
    return found;
}

Here is the caller graph for this function:

void TestingThread ( nux::NThread thread,
void *  user_data 
)

Definition at line 157 of file xtest-text-entry.cpp.

{
  while (test_textentry->ReadyToGo() == false)
  {
    nuxDebugMsg("Waiting to start");
    nux::SleepForMilliseconds(300);
  }

  nux::SleepForMilliseconds(1300);

  nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);

  NuxAutomatedTestFramework test(wnd_thread);

  test.Startup();

  test.TestReportMsg(test_textentry->text_entry_, "TextEntry created");

  test_textentry->ResetEvents();
  test.ViewSendMouseMotionToCenter(test_textentry->text_entry_);

  test.ViewSendMouseClick(0, 1);

  // Type "Nux"
  // The cursor is at the end of the line
  // Unset/Set the focus on the text entry
  // Move the cursor
  {
    test.ViewSendString("Nux");
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "Nux", "Typed \"Nux\"");

    test_textentry->GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(NULL); 
    test_textentry->GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(test_textentry->text_entry_);

    test_textentry->ResetEvents();
    test.ViewSendLeft();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->cursor_moved_, "Cursor moved.");

    test.ViewSendCtrlA();   
    test.ViewSendDelete();
  }

  // Type "Nux"
  // The cursor is at the end of the line
  // Unset/Set the focus on the text entry
  // Press enter
  {
    test.ViewSendString("Nux");
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "Nux", "Typed \"Nux\"");

    test_textentry->GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(NULL); 
    test_textentry->GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(test_textentry->text_entry_);

    test_textentry->ResetEvents();
    test.ViewSendReturn();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->activated_, "Activated.");

    test.ViewSendCtrlA();   
    test.ViewSendDelete();
  }

  // Type "Nux"
  // The cursor is at the end of the line
  // Simulate CTRL+A to select the entire text
  // Simulate DELETE key to delete the text
  {
    test.ViewSendString("Nux");
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "Nux", "Typed \"Nux\"");

    test.ViewSendCtrlA();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetTextSelection() == "Nux", "Selection is \"Nux\"");

   
    test.ViewSendDelete();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "TextEntry is empty");
  }

  // Type "0123456789"
  // The cursor is at the end of the line
  // Simulate BACKSPACE key until the text is enpty
  {
    test.ViewSendString("Ubuntu");
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "Ubuntu", "Typed \"Ubuntu\"");

    test.ViewSendBackspace();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "Ubunt", "Text is \"Ubunt\"");

    test.ViewSendBackspace();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "Ubun", "Text is \"Ubun\"");

    test.ViewSendBackspace();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "Ubu", "Text is \"Ubu\"");

    test.ViewSendBackspace();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "Ub", "Text is \"Ub\"");

    test.ViewSendBackspace();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "U", "Text is \"U\"");

    test.ViewSendBackspace();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "TextEntry is empty");
  }

  // Type "0123456789"
  // Move cursor to start of line
  // Simulate DELETE key until the text is 6789
  // Simulate CTRL+A to select the entire text
  // Simulate DELETE key to delete the text
  {
    test.ViewSendString("0123456789");
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "0123456789", "Typed \"0123456789\"");

    test_textentry->text_entry_->MoveCursorToLineStart();

    test.ViewSendDelete();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "123456789", "Text is \"123456789\"");

    test.ViewSendDelete();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "23456789", "Text is \"23456789\"");

    test.ViewSendDelete();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "3456789", "Text is \"3456789\"");

    test.ViewSendDelete();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "456789", "Text is \"456789\"");

    test.ViewSendDelete();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "56789", "Text is \"56789\"");

    test.ViewSendDelete();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "6789", "Text \"6789\"");


    test.ViewSendCtrlA();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetTextSelection() == "6789", "Selection is \"6789\"");

   
    test.ViewSendDelete();
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "TextEntry is empty");
  }

  // Send invalid keys
  {
    test.ViewSendKeyCombo(XK_Control_L, 0, 0, 'r');
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "Invalid key: TextEntry is empty");
    nux::SleepForMilliseconds(500);

    test.ViewSendKeyCombo(XK_Control_L, 0, 0, 'w');
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "Invalid key: TextEntry is empty");
    nux::SleepForMilliseconds(500);

    test.ViewSendKeyCombo(XK_Control_L, 0, 0, 'g');
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "Invalid key: TextEntry is empty");
    nux::SleepForMilliseconds(500);

    test.ViewSendKeyCombo(XK_Control_L, 0, 0, 'h');
    test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "Invalid key: TextEntry is empty");
    nux::SleepForMilliseconds(500);

    nux::SleepForMilliseconds(500);
    test.ViewSendCtrlA();
    test.ViewSendDelete();
  }

  // Toggle IBus
  // Type "qwerty"
  // Simulate key '1' to select the first IM option
  {
    // CTRL+Space to initiate iBus
    //test.ViewSendIBusToggle();
    
    IBusBus* bus_;
    ibus_init();
    bus_ = ibus_bus_new();
    bool active = false;
  
    // Test for ibus-pinyin 
    if (bus_ && SetEngineActive(bus_,"pinyin"))
    {
      // Type random stuff
      {
        test.ViewSendString("ninhao");
        nux::SleepForMilliseconds(500);
        test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "TextEntry is only Preedit");

        test.ViewSendChar('1');
        nux::SleepForMilliseconds(500);
        test.TestReportMsg(test_textentry->text_entry_->GetText() == "您好", "TextEntry is \"您好\"");

        test.ViewSendCtrlA();
        nux::SleepForMilliseconds(500);
        
        test.ViewSendDelete();
        nux::SleepForMilliseconds(500);
      }

      // Testing Cursor in the preedit window
      {
        test.ViewSendString("ming");
        nux::SleepForMilliseconds(500);
        test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "TextEntry is only Preedit");

        test.ViewSendLeft();
        nux::SleepForMilliseconds(500);

        test.ViewSendDelete();
        nux::SleepForMilliseconds(500);

        test.ViewSendChar('1');
        nux::SleepForMilliseconds(500);
        test.TestReportMsg(test_textentry->text_entry_->GetText() == "民", "TextEntry is \"民\"");

        test.ViewSendCtrlA();
        nux::SleepForMilliseconds(500);
        
        test.ViewSendDelete();
        nux::SleepForMilliseconds(500);
      }

      active = true;
    }

    // Test for ibus-hangul    
    if (bus_ && SetEngineActive(bus_,"hangul"))
    {   
      // Test for the the space in ibus-hangul working correctlly 
      {
        test.ViewSendString("asd abc ");
        nux::SleepForMilliseconds(500);
        test.TestReportMsg(test_textentry->text_entry_->GetText() == "ㅁㄴㅇ 뮻 ", "TextEntry is \"ㅁㄴㅇ 뮻 \"");

        test.ViewSendCtrlA();
        nux::SleepForMilliseconds(500);

        test.ViewSendDelete();
        nux::SleepForMilliseconds(500);
      }

      active = true;
    }

    // Checking for ibus-anthy - Japanese
    if (bus_ && SetEngineActive(bus_,"anthy"))
    {
      {
        test.ViewSendString("shisutemu ");
        nux::SleepForMilliseconds(500);
        test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "TextEntry is only Preedit");

        // Ctrl + J commits for ibus-anthy
        test.ViewSendKeyCombo(XK_Control_L, 0, 0, 'j');
        nux::SleepForMilliseconds(500);
        test.TestReportMsg(test_textentry->text_entry_->GetText() == "システム", "TextEntry is \"システム\"");

        test.ViewSendCtrlA();
        nux::SleepForMilliseconds(500);

        test.ViewSendDelete();

        nux::SleepForMilliseconds(500);
      }

      active = true;
    }

    g_object_unref (bus_); 

    // CTRL+Space to deactivate iBus
    if (active)
      test.ViewSendIBusToggle();
  }

  if (test.WhenDoneTerminateProgram())
  {
    wnd_thread->ExitMainLoop();
  }
  nuxDebugMsg("Exit testing thread");
}

Here is the call graph for this function:


Variable Documentation

Definition at line 155 of file xtest-text-entry.cpp.