-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[USDU-249] Adds test case for InitUSD #330
base: dev
Are you sure you want to change the base?
Changes from all commits
e8ef137
33342e6
a245e3d
06897df
7027e60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.IO; | ||
using NUnit.Framework; | ||
using System.Reflection; | ||
using Unity.Formats.USD; | ||
using UnityEngine; | ||
|
||
public class InitUsdTests | ||
{ | ||
[Test] | ||
[Ignore("[USDU-249]")] | ||
public void SetupUsdPath_InvalidPath_Error() | ||
{ | ||
var invalidFilePath = "\\NonExisting\\Path\\"; | ||
|
||
// SetupUsdPath function is a private function | ||
var setUpMethod = GetMethod("SetupUsdPath"); | ||
|
||
var expectedError = Assert.Throws<TargetInvocationException>(() => setUpMethod.Invoke(null, new object[] { invalidFilePath }), "Error was expected but not thrown"); | ||
Assert.IsInstanceOf<FileNotFoundException>(expectedError.InnerException); | ||
Assert.AreEqual(string.Format("Could not find file '{0}'.", invalidFilePath), expectedError.InnerException.Message, "Unexpected error message was given"); | ||
} | ||
|
||
[Test] | ||
public void SetupUsdPath_EmptyPath_Error() | ||
{ | ||
// SetupUsdPath function is a private function | ||
var setUpMethod = GetMethod("SetupUsdPath"); | ||
|
||
var expectedError = Assert.Throws<TargetInvocationException>(() => setUpMethod.Invoke(null, new object[] { "" }), "Error was expected but not thrown"); | ||
Assert.IsInstanceOf<System.ArgumentException>(expectedError.InnerException); | ||
Assert.AreEqual("The specified path is not of a legal form (empty).", expectedError.InnerException.Message, "Unexpected error message was given"); | ||
} | ||
|
||
[Test] | ||
public void InitUsd_Initialize() | ||
{ | ||
// Reset 'm_usdInitialized' for accurate testing | ||
ResetInitUsd(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that just changing the bool is enough here. Initialize() does stuff that might affect this test, such as setting up the UnityTypeBindings for USD. I'm not sure what the answer is though :D |
||
|
||
Assert.True(InitUsd.Initialize(), "USD Initialize failed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a more robust thing we can also check for, as well as the return value of Initialise()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eg check that the plugin is registered, that the expected debug log is printed, that no other errors are handled and logged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i've looked into this a bit more - on how to tell if the plugin has been registered and the typebinding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can check that unity types have been added the TypeBinder, that usd error message are logged in Unity console and that the plugins Registry is not empty. We can chat if you have more questions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @judubu - I will contact you via slack! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After talking with Julien, it turns out the PlugRegistry is not behaving correctly - created a separate JIRA ticket for this Will continue work on this PR after the above JIRA ticket has been solved |
||
} | ||
|
||
[TearDown] | ||
public void ResetInitUsd() | ||
{ | ||
var isUsdInitialized = typeof(InitUsd).GetField("m_usdInitialized", (BindingFlags.Static | BindingFlags.NonPublic)); | ||
isUsdInitialized.SetValue(null, false); | ||
} | ||
|
||
private MethodInfo GetMethod(string methodName) | ||
{ | ||
var method = typeof(InitUsd).GetMethod(methodName, (BindingFlags.NonPublic | BindingFlags.Static)); | ||
|
||
if (method == null) | ||
{ | ||
Assert.Fail(string.Format("{0} method not found", methodName)); | ||
} | ||
|
||
return method; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the expected result to the end of the test name, something like "InitUsd_Initialize_Succeeds"