Skip to content

Commit

Permalink
task(tests): add ability to clear persistent data in iOS test fixture (
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-bugsnag committed Aug 3, 2021
1 parent 926cb90 commit 1e52f66
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
26 changes: 13 additions & 13 deletions features/fixtures/maze_runner/Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -567,7 +567,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -641,7 +641,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -715,7 +715,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -1224,7 +1224,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 1
Expand Down Expand Up @@ -1810,7 +1810,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -1884,7 +1884,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -1958,7 +1958,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -2154,7 +2154,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -2323,7 +2323,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 1
Expand Down Expand Up @@ -2695,7 +2695,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -2891,7 +2891,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -2965,7 +2965,7 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 12800000, guid: a550dbcdb4abc4f53a3ca641d226e4a1, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
Expand Down
10 changes: 10 additions & 0 deletions features/fixtures/maze_runner/Assets/Scripts/MobileNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class MobileNative : MonoBehaviour {
[DllImport("__Internal")]
private static extern void TriggerCocoaCppException();

[DllImport("__Internal")]
private static extern void ClearPersistentData();

#endif

public static void Crash()
Expand Down Expand Up @@ -37,6 +40,13 @@ private static void IOSCrash()
#endif
}

public static void ClearPersistantData()
{
#if UNITY_IOS
ClearPersistentData();
#endif
}

public static void TriggerJvmException()
{
if (Application.platform == RuntimePlatform.Android)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class MobileScenarioRunner : MonoBehaviour {
{"11", "Max Breadcrumbs" },
{"12", "Disable Native Errors" },
{"13", "throw Exception with breadcrumbs" },
{"14", "Start SDK no errors" }
{"14", "Start SDK no errors" },
{"15", "Clear iOS Data" }


};

Expand Down Expand Up @@ -161,6 +163,9 @@ public void DoTestAction(string scenarioName)
LeaveFiveBreadcrumbs();
ThrowException();
break;
case "Clear iOS Data":
MobileNative.ClearPersistantData();
break;
default:
throw new System.Exception("Unknown scenario: " + scenarioName);

Expand Down
20 changes: 20 additions & 0 deletions features/fixtures/maze_runner/Assets/nativeplugin/native_code.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,28 @@
void RaiseCocoaSignal();
void TriggerCocoaCppException();
void TriggerCocoaAppHang();
void ClearPersistentData();
}





void ClearPersistentData() {
NSLog(@"Clear persistent data");
[NSUserDefaults.standardUserDefaults removePersistentDomainForName:NSBundle.mainBundle.bundleIdentifier];
NSString *appSupportDir = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).firstObject;
NSString *rootDir = [appSupportDir stringByAppendingPathComponent:@"com.bugsnag.Bugsnag"];
NSError *error = nil;
if (![NSFileManager.defaultManager removeItemAtPath:rootDir error:&error]) {
if (![error.domain isEqual:NSCocoaErrorDomain] && error.code != NSFileNoSuchFileError) {
NSLog(@"%@", error);
}
}
}



void RaiseCocoaSignal() {
abort();
}
Expand Down
3 changes: 2 additions & 1 deletion features/steps/unity_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"Max Breadcrumbs" => 11,
"Disable Native Errors" => 12,
"throw Exception with breadcrumbs" => 13,
"Start SDK no errors" => 14
"Start SDK no errors" => 14,
"Clear iOS Data" => 15
}
number = lookup[scenario]
$logger.debug "#{scenario}' has dial-in code #{number}"
Expand Down

0 comments on commit 1e52f66

Please sign in to comment.