Imported Upstream version 1.4.6
[platform/upstream/harfbuzz.git] / test / api / test-font.c
index 6b6a503..527dfcd 100644 (file)
@@ -35,13 +35,23 @@ static const char test_data[] = "test\0data";
 static void
 test_face_empty (void)
 {
+  hb_face_t *created_from_empty;
+  hb_face_t *created_from_null;
+
   g_assert (hb_face_get_empty ());
-  g_assert (hb_face_get_empty () == hb_face_create (hb_blob_get_empty (), 0));
-  g_assert (hb_face_get_empty () == hb_face_create (NULL, 0));
+
+  created_from_empty = hb_face_create (hb_blob_get_empty (), 0);
+  g_assert (hb_face_get_empty () != created_from_empty);
+
+  created_from_null = hb_face_create (NULL, 0);
+  g_assert (hb_face_get_empty () != created_from_null);
 
   g_assert (hb_face_reference_table (hb_face_get_empty (), HB_TAG ('h','e','a','d')) == hb_blob_get_empty ());
 
   g_assert_cmpint (hb_face_get_upem (hb_face_get_empty ()), ==, 1000);
+
+  hb_face_destroy (created_from_null);
+  hb_face_destroy (created_from_empty);
 }
 
 static void
@@ -115,6 +125,7 @@ _test_font_nil_funcs (hb_font_t *font)
   hb_codepoint_t glyph;
   hb_position_t x, y;
   hb_glyph_extents_t extents;
+  unsigned int upem = hb_face_get_upem (hb_font_get_face (font));
 
   x = y = 13;
   g_assert (!hb_font_get_glyph_contour_point (font, 17, 2, &x, &y));
@@ -122,7 +133,7 @@ _test_font_nil_funcs (hb_font_t *font)
   g_assert_cmpint (y, ==, 0);
 
   x = hb_font_get_glyph_h_advance (font, 17);
-  g_assert_cmpint (x, ==, 0);
+  g_assert_cmpint (x, ==, upem);
 
   extents.x_bearing = extents.y_bearing = 13;
   extents.width = extents.height = 15;
@@ -290,9 +301,22 @@ test_fontfuncs_subclassing (void)
   x = hb_font_get_glyph_h_advance (font1, 2);
   g_assert_cmpint (x, ==, 0);
 
-
+  /* creating sub-font doesn't make the parent font immutable;
+   * making a font immutable however makes it's lineage immutable.
+   */
   font2 = hb_font_create_sub_font (font1);
+  font3 = hb_font_create_sub_font (font2);
+  g_assert (!hb_font_is_immutable (font1));
+  g_assert (!hb_font_is_immutable (font2));
+  g_assert (!hb_font_is_immutable (font3));
+  hb_font_make_immutable (font3);
   g_assert (hb_font_is_immutable (font1));
+  g_assert (hb_font_is_immutable (font2));
+  g_assert (hb_font_is_immutable (font3));
+  hb_font_destroy (font2);
+  hb_font_destroy (font3);
+
+  font2 = hb_font_create_sub_font (font1);
   hb_font_destroy (font1);
 
   /* setup font2 to override some funcs */
@@ -316,12 +340,8 @@ test_fontfuncs_subclassing (void)
   x = hb_font_get_glyph_h_advance (font2, 2);
   g_assert_cmpint (x, ==, 0);
 
-
-  font3 = hb_font_create_sub_font (font2);
-  g_assert (hb_font_is_immutable (font2));
-  hb_font_destroy (font2);
-
   /* setup font3 to override scale */
+  font3 = hb_font_create_sub_font (font2);
   hb_font_set_scale (font3, 20, 30);
 
   x = y = 1;
@@ -347,14 +367,29 @@ test_fontfuncs_subclassing (void)
 static void
 test_font_empty (void)
 {
+  hb_font_t *created_from_empty;
+  hb_font_t *created_from_null;
+  hb_font_t *created_sub_from_null;
+
   g_assert (hb_font_get_empty ());
-  g_assert (hb_font_get_empty () == hb_font_create (hb_face_get_empty ()));
-  g_assert (hb_font_get_empty () == hb_font_create (NULL));
-  g_assert (hb_font_get_empty () == hb_font_create_sub_font (NULL));
+
+  created_from_empty = hb_font_create (hb_face_get_empty ());
+  g_assert (hb_font_get_empty () != created_from_empty);
+
+  created_from_null = hb_font_create (NULL);
+  g_assert (hb_font_get_empty () != created_from_null);
+
+  created_sub_from_null = hb_font_create_sub_font (NULL);
+  g_assert (hb_font_get_empty () != created_sub_from_null);
+
   g_assert (hb_font_is_immutable (hb_font_get_empty ()));
 
   g_assert (hb_font_get_face (hb_font_get_empty ()) == hb_face_get_empty ());
   g_assert (hb_font_get_parent (hb_font_get_empty ()) == NULL);
+
+  hb_font_destroy (created_sub_from_null);
+  hb_font_destroy (created_from_null);
+  hb_font_destroy (created_from_empty);
 }
 
 static void
@@ -366,6 +401,7 @@ test_font_properties (void)
   hb_font_t *subfont;
   int x_scale, y_scale;
   unsigned int x_ppem, y_ppem;
+  unsigned int upem;
 
   blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL);
   face = hb_face_create (blob, 0);
@@ -375,22 +411,35 @@ test_font_properties (void)
 
 
   g_assert (hb_font_get_face (font) == face);
-  g_assert (hb_font_get_parent (font) == NULL);
+  g_assert (hb_font_get_parent (font) == hb_font_get_empty ());
+  subfont = hb_font_create_sub_font (font);
+  g_assert (hb_font_get_parent (subfont) == font);
+  hb_font_set_parent(subfont, NULL);
+  g_assert (hb_font_get_parent (subfont) == hb_font_get_empty());
+  hb_font_set_parent(subfont, font);
+  g_assert (hb_font_get_parent (subfont) == font);
+  hb_font_set_parent(subfont, NULL);
+  hb_font_make_immutable (subfont);
+  g_assert (hb_font_get_parent (subfont) == hb_font_get_empty());
+  hb_font_set_parent(subfont, font);
+  g_assert (hb_font_get_parent (subfont) == hb_font_get_empty());
+  hb_font_destroy (subfont);
 
 
   /* Check scale */
 
+  upem = hb_face_get_upem (hb_font_get_face (font));
   hb_font_get_scale (font, NULL, NULL);
   x_scale = y_scale = 13;
   hb_font_get_scale (font, &x_scale, NULL);
-  g_assert_cmpint (x_scale, ==, 0);
+  g_assert_cmpint (x_scale, ==, upem);
   x_scale = y_scale = 13;
   hb_font_get_scale (font, NULL, &y_scale);
-  g_assert_cmpint (y_scale, ==, 0);
+  g_assert_cmpint (y_scale, ==, upem);
   x_scale = y_scale = 13;
   hb_font_get_scale (font, &x_scale, &y_scale);
-  g_assert_cmpint (x_scale, ==, 0);
-  g_assert_cmpint (y_scale, ==, 0);
+  g_assert_cmpint (x_scale, ==, upem);
+  g_assert_cmpint (y_scale, ==, upem);
 
   hb_font_set_scale (font, 17, 19);