FbxDouble4x4Test.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // ***********************************************************************
  2. // Copyright (c) 2017 Unity Technologies. All rights reserved.
  3. //
  4. // Licensed under the ##LICENSENAME##.
  5. // See LICENSE.md file in the project root for full license information.
  6. // ***********************************************************************
  7. using NUnit.Framework;
  8. using Autodesk.Fbx;
  9. namespace Autodesk.Fbx.UnitTests
  10. {
  11. public class FbxDouble4x4TestBase<T> : TestBase<T> where T: FbxDouble4x4
  12. {
  13. /// <summary>
  14. /// Test element access and Dispose().
  15. /// The 'mx' matrix is invalid after this.
  16. /// </summary>
  17. protected void TestElementAccessAndDispose(T mx)
  18. {
  19. var a = new FbxDouble4(1,2,3,4);
  20. var b = new FbxDouble4(5,6,7,8);
  21. var c = new FbxDouble4(9,8,7,6);
  22. var d = new FbxDouble4(5,4,3,2);
  23. mx.X = d;
  24. mx.Y = c;
  25. mx.Z = b;
  26. mx.W = a;
  27. Assert.AreEqual(d, mx.X);
  28. Assert.AreEqual(c, mx.Y);
  29. Assert.AreEqual(b, mx.Z);
  30. Assert.AreEqual(a, mx.W);
  31. mx[0] = a;
  32. mx[1] = b;
  33. mx[2] = c;
  34. mx[3] = d;
  35. Assert.AreEqual(a, mx[0]);
  36. Assert.AreEqual(b, mx[1]);
  37. Assert.AreEqual(c, mx[2]);
  38. Assert.AreEqual(d, mx[3]);
  39. Assert.That(() => mx[-1], Throws.Exception.TypeOf<System.ArgumentOutOfRangeException>());
  40. Assert.That(() => mx[ 4], Throws.Exception.TypeOf<System.ArgumentOutOfRangeException>());
  41. Assert.That(() => mx[-1] = a, Throws.Exception.TypeOf<System.ArgumentOutOfRangeException>());
  42. Assert.That(() => mx[ 4] = a, Throws.Exception.TypeOf<System.ArgumentOutOfRangeException>());
  43. mx.Dispose();
  44. }
  45. }
  46. public class FbxDouble4x4Test : FbxDouble4x4TestBase<FbxDouble4x4>
  47. {
  48. [Test]
  49. public void TestEquality()
  50. {
  51. var a = new FbxDouble4(1,2,3,4);
  52. var b = new FbxDouble4(5,6,7,8);
  53. var c = new FbxDouble4(9,8,7,6);
  54. var d = new FbxDouble4(5,4,3,2);
  55. EqualityTester<FbxDouble4x4>.TestEquality(
  56. new FbxDouble4x4(a, b, c, d),
  57. new FbxDouble4x4(d, c, b, a),
  58. new FbxDouble4x4(a, b, c, d));
  59. }
  60. /// <summary>
  61. /// Test the basics. Subclasses should override and add some calls
  62. /// e.g. to excercise all the constructors.
  63. /// </summary>
  64. [Test]
  65. public void TestBasics()
  66. {
  67. FbxDouble4x4 v;
  68. // We use these later.
  69. var a = new FbxDouble4(1,2,3,4);
  70. var b = new FbxDouble4(5,6,7,8);
  71. var c = new FbxDouble4(9,8,7,6);
  72. var d = new FbxDouble4(5,4,3,2);
  73. // make sure the no-arg constructor doesn't crash
  74. new FbxDouble4x4();
  75. // make sure we can dispose
  76. using (new FbxDouble4x4()) { }
  77. new FbxDouble4x4().Dispose();
  78. // Test that we can get elements and we can dispose.
  79. // Also tests the 4-arg constructor.
  80. base.TestElementAccessAndDispose(new FbxDouble4x4());
  81. // Test copy constructor
  82. v = new FbxDouble4x4(a,b,c,d);
  83. var u = new FbxDouble4x4(v);
  84. Assert.AreEqual(v, u);
  85. u[0] = c;
  86. Assert.AreEqual(c, u[0]);
  87. Assert.AreEqual(a, v[0]); // check that setting u doesn't set v
  88. // Test one-element constructor.
  89. v = new FbxDouble4x4(c);
  90. Assert.AreEqual(c, v[0]);
  91. Assert.AreEqual(c, v[1]);
  92. Assert.AreEqual(c, v[2]);
  93. Assert.AreEqual(c, v[3]);
  94. }
  95. }
  96. }