diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gtests/blenlib/BLI_listbase_test.cc | 39 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_math_color_test.cc | 14 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_math_geom_test.cc | 4 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_path_util_test.cc | 6 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_stack_test.cc | 13 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_string_test.cc | 34 | ||||
-rw-r--r-- | tests/gtests/blenlib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/python/bl_mesh_modifiers.py | 5 | ||||
-rw-r--r-- | tests/python/bl_pyapi_mathutils.py | 44 | ||||
-rw-r--r-- | tests/python/bl_pyapi_units.py | 23 |
10 files changed, 134 insertions, 50 deletions
diff --git a/tests/gtests/blenlib/BLI_listbase_test.cc b/tests/gtests/blenlib/BLI_listbase_test.cc new file mode 100644 index 00000000000..4b4d5d80a43 --- /dev/null +++ b/tests/gtests/blenlib/BLI_listbase_test.cc @@ -0,0 +1,39 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +extern "C" { +#include "BLI_listbase.h" +#include "MEM_guardedalloc.h" +} + +TEST(listbase, FindLinkOrIndex) +{ + ListBase lb; + void *link1 = MEM_callocN(sizeof(Link), "link1"); + void *link2 = MEM_callocN(sizeof(Link), "link2"); + + /* Empty list */ + BLI_listbase_clear(&lb); + EXPECT_EQ(NULL, BLI_findlink(&lb, -1)); + EXPECT_EQ(NULL, BLI_findlink(&lb, 0)); + EXPECT_EQ(NULL, BLI_findlink(&lb, 1)); + EXPECT_EQ(NULL, BLI_rfindlink(&lb, -1)); + EXPECT_EQ(NULL, BLI_rfindlink(&lb, 0)); + EXPECT_EQ(NULL, BLI_rfindlink(&lb, 1)); + EXPECT_EQ(-1, BLI_findindex(&lb, link1)); + + /* One link */ + BLI_addtail(&lb, link1); + EXPECT_EQ(link1, BLI_findlink(&lb, 0)); + EXPECT_EQ(link1, BLI_rfindlink(&lb, 0)); + EXPECT_EQ(0, BLI_findindex(&lb, link1)); + + /* Two links */ + BLI_addtail(&lb, link2); + EXPECT_EQ(link2, BLI_findlink(&lb, 1)); + EXPECT_EQ(link2, BLI_rfindlink(&lb, 0)); + EXPECT_EQ(1, BLI_findindex(&lb, link2)); + + BLI_freelistN(&lb); +} diff --git a/tests/gtests/blenlib/BLI_math_color_test.cc b/tests/gtests/blenlib/BLI_math_color_test.cc index be6d7c6a55f..2118822a9d8 100644 --- a/tests/gtests/blenlib/BLI_math_color_test.cc +++ b/tests/gtests/blenlib/BLI_math_color_test.cc @@ -4,7 +4,7 @@ #include "BLI_math.h" -TEST(mathutils, RGBToHSVRoundtrip) +TEST(math_color, RGBToHSVRoundtrip) { float orig_rgb[3] = {0.1f, 0.2f, 0.3f}; float hsv[3], rgb[3]; @@ -13,7 +13,7 @@ TEST(mathutils, RGBToHSVRoundtrip) EXPECT_V3_NEAR(orig_rgb, rgb, 1e-5); } -TEST(mathutils, RGBToHSLRoundtrip) +TEST(math_color, RGBToHSLRoundtrip) { float orig_rgb[3] = {0.1f, 0.2f, 0.3f}; float hsl[3], rgb[3]; @@ -22,7 +22,7 @@ TEST(mathutils, RGBToHSLRoundtrip) EXPECT_V3_NEAR(orig_rgb, rgb, 1e-5); } -TEST(mathutils, RGBToYUVRoundtrip) +TEST(math_color, RGBToYUVRoundtrip) { float orig_rgb[3] = {0.1f, 0.2f, 0.3f}; float yuv[3], rgb[3]; @@ -33,7 +33,7 @@ TEST(mathutils, RGBToYUVRoundtrip) EXPECT_V3_NEAR(orig_rgb, rgb, 1e-4); } -TEST(mathutils, RGBToYCCRoundtrip) +TEST(math_color, RGBToYCCRoundtrip) { float orig_rgb[3] = {0.1f, 0.2f, 0.3f}; float ycc[3], rgb[3]; @@ -63,21 +63,21 @@ TEST(mathutils, RGBToYCCRoundtrip) EXPECT_V3_NEAR(orig_rgb, rgb, 1e-3); } -TEST(mathutils, LinearRGBTosRGBNearZero) +TEST(math_color, LinearRGBTosRGBNearZero) { float linear_color = 0.002f; float srgb_color = linearrgb_to_srgb(linear_color); EXPECT_NEAR(0.02584f, srgb_color, 1e-5); } -TEST(mathutils, LinearRGBTosRGB) +TEST(math_color, LinearRGBTosRGB) { float linear_color = 0.75f; float srgb_color = linearrgb_to_srgb(linear_color); EXPECT_NEAR(0.880824f, srgb_color, 1e-5); } -TEST(mathutils, LinearRGBTosRGBRoundtrip) +TEST(math_color, LinearRGBTosRGBRoundtrip) { const int N = 50; int i; diff --git a/tests/gtests/blenlib/BLI_math_geom_test.cc b/tests/gtests/blenlib/BLI_math_geom_test.cc index 2f85e6b4d7d..cd15a4eb8ff 100644 --- a/tests/gtests/blenlib/BLI_math_geom_test.cc +++ b/tests/gtests/blenlib/BLI_math_geom_test.cc @@ -4,7 +4,7 @@ #include "BLI_math.h" -TEST(mathutils, DistToLine2DSimple) +TEST(math_geom, DistToLine2DSimple) { float p[2] = {5.0f, 1.0f}, a[2] = {0.0f, 0.0f}, @@ -13,7 +13,7 @@ TEST(mathutils, DistToLine2DSimple) EXPECT_NEAR(1.0f, distance, 1e-6); } -TEST(mathutils, DistToLineSegment2DSimple) +TEST(math_geom, DistToLineSegment2DSimple) { float p[2] = {3.0f, 1.0f}, a[2] = {0.0f, 0.0f}, diff --git a/tests/gtests/blenlib/BLI_path_util_test.cc b/tests/gtests/blenlib/BLI_path_util_test.cc index e3a3699e5c1..ea761bcf32e 100644 --- a/tests/gtests/blenlib/BLI_path_util_test.cc +++ b/tests/gtests/blenlib/BLI_path_util_test.cc @@ -46,7 +46,7 @@ char *zLhm65070058860608_br_find_exe(const char *default_exe) /* tests */ /* BLI_cleanup_path */ -TEST(pathutils, PathUtilClean) +TEST(path_util, PathUtilClean) { /* "/./" -> "/" */ { @@ -102,7 +102,7 @@ TEST(pathutils, PathUtilClean) } /* BLI_path_frame */ -TEST(pathutils, PathUtilFrame) +TEST(path_util, PathUtilFrame) { bool ret; @@ -165,7 +165,7 @@ TEST(pathutils, PathUtilFrame) } /* BLI_split_dirfile */ -TEST(pathutils, PathUtilSplitDirfile) +TEST(path_util, PathUtilSplitDirfile) { { const char *path = ""; diff --git a/tests/gtests/blenlib/BLI_stack_test.cc b/tests/gtests/blenlib/BLI_stack_test.cc index 8ad4d957813..c4884cb8940 100644 --- a/tests/gtests/blenlib/BLI_stack_test.cc +++ b/tests/gtests/blenlib/BLI_stack_test.cc @@ -17,6 +17,7 @@ TEST(stack, Empty) stack = BLI_stack_new(sizeof(int), __func__); EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_EQ(BLI_stack_count(stack), 0); BLI_stack_free(stack); } @@ -29,9 +30,11 @@ TEST(stack, One) BLI_stack_push(stack, (void *)&in); EXPECT_EQ(BLI_stack_is_empty(stack), false); + EXPECT_EQ(BLI_stack_count(stack), 1); BLI_stack_pop(stack, (void *)&out); EXPECT_EQ(in, out); EXPECT_EQ(BLI_stack_is_empty(stack), true); + EXPECT_EQ(BLI_stack_count(stack), 0); BLI_stack_free(stack); } @@ -79,7 +82,6 @@ TEST(stack, String) *((int *)in) = i; BLI_stack_pop(stack, (void *)&out); EXPECT_STREQ(in, out); - } EXPECT_EQ(BLI_stack_is_empty(stack), true); @@ -133,5 +135,14 @@ TEST(stack, Reuse) EXPECT_EQ(i, 0); EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0); + + /* finally test BLI_stack_pop_n */ + for (i = ARRAY_SIZE(sizes); i--; ) { + BLI_stack_push(stack, (void *)&sizes[i]); + } + EXPECT_EQ(BLI_stack_count(stack), ARRAY_SIZE(sizes)); + BLI_stack_pop_n(stack, (void *)sizes_test, ARRAY_SIZE(sizes)); + EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0); + BLI_stack_free(stack); } diff --git a/tests/gtests/blenlib/BLI_string_test.cc b/tests/gtests/blenlib/BLI_string_test.cc index 13091d9e074..4c5c410dcb2 100644 --- a/tests/gtests/blenlib/BLI_string_test.cc +++ b/tests/gtests/blenlib/BLI_string_test.cc @@ -267,3 +267,37 @@ TEST(string, StrRPartitionUtf8) EXPECT_EQ(NULL, suf); } } + +/* BLI_str_format_int_grouped */ +TEST(string, StrFormatIntGrouped) +{ + char num_str[16]; + int num; + + BLI_str_format_int_grouped(num_str, num = 0); + EXPECT_STREQ("0", num_str); + + BLI_str_format_int_grouped(num_str, num = 1); + EXPECT_STREQ("1", num_str); + + BLI_str_format_int_grouped(num_str, num = -1); + EXPECT_STREQ("-1", num_str); + + BLI_str_format_int_grouped(num_str, num = -2147483648); + EXPECT_STREQ("-2,147,483,648", num_str); + + BLI_str_format_int_grouped(num_str, num = 2147483647); + EXPECT_STREQ("2,147,483,647", num_str); + + BLI_str_format_int_grouped(num_str, num = 1000); + EXPECT_STREQ("1,000", num_str); + + BLI_str_format_int_grouped(num_str, num = -1000); + EXPECT_STREQ("-1,000", num_str); + + BLI_str_format_int_grouped(num_str, num = 999); + EXPECT_STREQ("999", num_str); + + BLI_str_format_int_grouped(num_str, num = -999); + EXPECT_STREQ("-999", num_str); +} diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt index d55fdd1cd2a..07b89a9042e 100644 --- a/tests/gtests/blenlib/CMakeLists.txt +++ b/tests/gtests/blenlib/CMakeLists.txt @@ -25,6 +25,7 @@ set(INC . .. ../../../source/blender/blenlib + ../../../source/blender/makesdna ../../../intern/guardedalloc ) @@ -39,3 +40,4 @@ BLENDER_TEST(BLI_math_color "bf_blenlib") BLENDER_TEST(BLI_math_geom "bf_blenlib") BLENDER_TEST(BLI_string "bf_blenlib") BLENDER_TEST(BLI_path_util "bf_blenlib;extern_wcwidth;${ZLIB_LIBRARIES}") +BLENDER_TEST(BLI_listbase "bf_blenlib") diff --git a/tests/python/bl_mesh_modifiers.py b/tests/python/bl_mesh_modifiers.py index b3f77aed96b..1c05eaafa0d 100644 --- a/tests/python/bl_mesh_modifiers.py +++ b/tests/python/bl_mesh_modifiers.py @@ -434,11 +434,6 @@ def modifier_hook_add(scene, obj, use_vgroup=True): for v in mesh.vertices: v.select = False - if IS_BMESH: - face_verts = mesh_bmesh_poly_vertices(mesh.polygons[0]) - else: - face_verts = mesh.faces[0].vertices[:] - for i in mesh.faces[0].vertices: mesh.vertices[i].select = True diff --git a/tests/python/bl_pyapi_mathutils.py b/tests/python/bl_pyapi_mathutils.py index d204e58dbd4..85232e465d7 100644 --- a/tests/python/bl_pyapi_mathutils.py +++ b/tests/python/bl_pyapi_mathutils.py @@ -1,8 +1,7 @@ # Apache License, Version 2.0 -# ./blender.bin --background -noaudio --python tests/python/bl_pyapi_mathutils.py +# ./blender.bin --background -noaudio --python tests/python/bl_pyapi_mathutils.py -- --verbose import unittest -from test import support from mathutils import Matrix, Vector from mathutils import kdtree import math @@ -163,6 +162,29 @@ class MatrixTesting(unittest.TestCase): self.assertEqual(mat.inverted(), inv_mat) + def test_matrix_inverse_safe(self): + mat = Matrix(((1, 4, 0, -1), + (2, -1, 0, -2), + (0, 3, 0, 3), + (-2, 9, 0, 0))) + + # Warning, if we change epsilon in py api we have to update this!!! + epsilon = 1e-8 + inv_mat_safe = mat.copy() + inv_mat_safe[0][0] += epsilon + inv_mat_safe[1][1] += epsilon + inv_mat_safe[2][2] += epsilon + inv_mat_safe[3][3] += epsilon + inv_mat_safe.invert() + ''' + inv_mat_safe = Matrix(((1.0, -0.5, 0.0, -0.5), + (0.222222, -0.111111, -0.0, 0.0), + (-333333344.0, 316666656.0, 100000000.0, 150000000.0), + (0.888888, -0.9444444, 0.0, -0.5))) + ''' + + self.assertEqual(mat.inverted_safe(), inv_mat_safe) + def test_matrix_mult(self): mat = Matrix(((1, 4, 0, -1), (2, -1, 2, -2), @@ -291,19 +313,7 @@ class KDTreeTesting(unittest.TestCase): with self.assertRaises(RuntimeError): k.find(co) - -def test_main(): - try: - support.run_unittest(MatrixTesting) - support.run_unittest(VectorTesting) - support.run_unittest(KDTreeTesting) - except: - import traceback - traceback.print_exc() - - # alert CTest we failed - import sys - sys.exit(1) - if __name__ == '__main__': - test_main() + import sys + sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []) + unittest.main() diff --git a/tests/python/bl_pyapi_units.py b/tests/python/bl_pyapi_units.py index 478adef51b2..128cc100b25 100644 --- a/tests/python/bl_pyapi_units.py +++ b/tests/python/bl_pyapi_units.py @@ -1,8 +1,7 @@ # Apache License, Version 2.0 -# ./blender.bin --background -noaudio --python tests/python/bl_pyapi_units.py +# ./blender.bin --background -noaudio --python tests/python/bl_pyapi_units.py -- --verbose import unittest -from test import support from bpy.utils import units @@ -23,7 +22,10 @@ class UnitsTesting(unittest.TestCase): ('METRIC', 'LENGTH', "33.3dm", "1", 0.1), ('IMPERIAL', 'LENGTH', "33.3cm", "1", 0.3048), # ref unit is not in IMPERIAL system, default to feet... ('IMPERIAL', 'LENGTH', "33.3ft", "1\"", 0.0254), # unused ref unit, since one is given already! - #('IMPERIAL', 'LENGTH', "", "1+1ft", 0.3048 * 2), # Will fail with current code! + ('IMPERIAL', 'LENGTH', "", "1+1ft", 0.3048 * 2), # default unit taken from current string (feet). + ('METRIC', 'LENGTH', "", "1+1ft", 1.3048), # no metric units, we default to meters. + ('IMPERIAL', 'LENGTH', "", "3+1in+1ft", 0.3048 * 4 + 0.0254), # bigger unit becomes default one! + ('IMPERIAL', 'LENGTH', "", "(3+1)in+1ft", 0.3048 + 0.0254 * 4), ) # From 'internal' Blender value to user-friendly printing @@ -67,16 +69,7 @@ class UnitsTesting(unittest.TestCase): "\"%s\", expected \"%s\"" % (usys, utype, val, prec, sep, compat, opt_str, output)) -def test_main(): - try: - support.run_unittest(UnitsTesting) - except: - import traceback - traceback.print_exc() - - # alert CTest we failed - import sys - sys.exit(1) - if __name__ == '__main__': - test_main() + import sys + sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []) + unittest.main() |