Back to index

unity  6.0.0
Defines | Functions
TestStaticCairoText.cpp File Reference
#include "config.h"
#include <glib.h>
#include <pango/pango.h>
#include "Nux/Nux.h"
#include "StaticCairoText.h"

Go to the source code of this file.

Defines

#define _DOMAIN   "/Unit/StaticCairoText"

Functions

static void switch_language (const char *new_locale)
static void assert_width_increases_with_substring_length (const gchar *test_string)
static void TestLeftToRightExtentIncreasesWithLength ()
static void TestRightToLeftExtentIncreasesWithLength ()
void TestStaticCairoTextCreateSuite ()

Define Documentation

#define _DOMAIN   "/Unit/StaticCairoText"

Function Documentation

static void assert_width_increases_with_substring_length ( const gchar *  test_string) [static]

Definition at line 45 of file TestStaticCairoText.cpp.

{
  nux::StaticCairoText text("");
  gchar *substring = new gchar[strlen(test_string)];

  int width, oldwidth;
  int height;

  text.GetTextExtents(width, height);
  // The empty string should have no width...
  g_assert_cmpint (width, ==, 0);
  oldwidth = width;

  for (int substr_len = 1; substr_len <= g_utf8_strlen(test_string, -1); ++substr_len) {
    text.SetText (g_utf8_strncpy (substring, test_string, substr_len));
    text.GetTextExtents(width, height);
    g_assert_cmpint(width, >, oldwidth);
    oldwidth = width;
  }
  
  delete substring;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void switch_language ( const char *  new_locale) [static]

Definition at line 30 of file TestStaticCairoText.cpp.

{
  setenv ("LANGUAGE", new_locale, 1);

  /*
   * The GNU gettext manual suggests this is necessary to ensure the gettext
   * cache doesn't interfere with the locale change
   */
  {
    extern int _nl_msg_cat_cntr;
    ++_nl_msg_cat_cntr;
  }
}

Here is the caller graph for this function:

static void TestLeftToRightExtentIncreasesWithLength ( ) [static]

Definition at line 69 of file TestStaticCairoText.cpp.

{
  const gchar *test_string = "Just a string of text";
  
  switch_language("en");

  g_assert(g_utf8_validate(test_string, -1, NULL));
  g_assert(pango_find_base_dir(test_string, -1) == PANGO_DIRECTION_LTR);

  assert_width_increases_with_substring_length (test_string);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestRightToLeftExtentIncreasesWithLength ( ) [static]

Definition at line 82 of file TestStaticCairoText.cpp.

{
  // This is the UTF-8 encoding of מחרוזת אקראית עברית, a hebrew test string.
  const gchar *test_string = "\xd7\x9e\xd7\x97\xd7\xa8\xd7\x95\xd7\x96\xd7\xaa"
                             " \xd7\x90\xd7\xa7\xd7\xa8\xd7\x90\xd7\x99\xd7\xaa"
                             "\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa";

  // Hebrew is an RTL language
  switch_language("he");

  g_assert(g_utf8_validate(test_string, -1, NULL));
  g_assert(pango_find_base_dir(test_string, -1) == PANGO_DIRECTION_RTL);
  
  assert_width_increases_with_substring_length (test_string);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 99 of file TestStaticCairoText.cpp.

{
#define _DOMAIN "/Unit/StaticCairoText"

  g_test_add_func(_DOMAIN"/TextLeftToRightExtentIncreasesWithLength", TestLeftToRightExtentIncreasesWithLength);
  g_test_add_func(_DOMAIN"/TestRightToLeftExtentIncreasesWithLength", TestRightToLeftExtentIncreasesWithLength);
}

Here is the call graph for this function:

Here is the caller graph for this function: