Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Add binding unit tests for cocos2d
Browse files Browse the repository at this point in the history
  • Loading branch information
spouliot committed Jan 29, 2013
1 parent e1c9b87 commit 2205a37
Show file tree
Hide file tree
Showing 10 changed files with 526 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cocos2d/binding-test/BindingCtorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2013 Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Reflection;

using NUnit.Framework;
using TouchUnit.Bindings;

using MonoTouch.Cocos2D;
using MonoTouch.Foundation;

namespace Cocos2D.Bindings {

[TestFixture]
public class BindingCtorTest : ApiCtorInitTest {

public BindingCtorTest ()
{
// Useful to know what was being tested if the application crash
// LogProgress = true;

// Useful for fixing several errors before rebuilding the bindings
// ContinueOnFailure = true;

// Useful to know which types are being skipped for lack of a default ctor
// LogUntestedTypes = true;
}

protected override Assembly Assembly {
get { return typeof (CCAccelAmplitude).Assembly; }
}
}
}
47 changes: 47 additions & 0 deletions cocos2d/binding-test/BindingFieldTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2013 Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Reflection;

using NUnit.Framework;
using TouchUnit.Bindings;

using MonoTouch.Cocos2D;
using MonoTouch.Foundation;

namespace Cocos2D.Bindings {

[TestFixture]
public class BindingFieldTest : ApiFieldTest {

public BindingFieldTest ()
{
// Useful to know what was being tried if things crash
// LogProgress = true;

// Useful for fixing several errors before rebuilding the bindings
// ContinueOnFailure = true;
}

protected override Assembly Assembly {
get { return typeof (CCAccelAmplitude).Assembly; }
}
}
}
77 changes: 77 additions & 0 deletions cocos2d/binding-test/BindingSelectorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2013 Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Reflection;

using NUnit.Framework;
using TouchUnit.Bindings;

using MonoTouch.Cocos2D;

namespace Cocos2D.Bindings {

[TestFixture]
public class BindingSelectorTest : ApiSelectorTest {

public BindingSelectorTest ()
{
// Useful to know what was being tried if things crash
// LogProgress = true;

// Useful for fixing several errors before rebuilding the bindings
// ContinueOnFailure = true;
}

protected override Assembly Assembly {
get { return typeof (CCAccelAmplitude).Assembly; }
}

protected override bool Skip (Type type, string selectorName)
{
switch (selectorName) {
// CCRGBAProtocol
case "doesOpacityModifyRGB":
case "opacityModifyRGB:":
switch (type.Name) {
case "CCAtlasNode":
case "CCLabelBMFont":
case "CCLayerColor":
case "CCMenu":
case "CCMenuItemLabel":
case "CCMenuItemSprite":
case "CCMenuItemToggle":
case "CCSprite":
return true;
}
break;
// CCTargetedTouchDelegate
case "ccTouchMoved:withEvent:":
case "ccTouchEnded:withEvent:":
case "ccTouchCancelled:withEvent:":
case "ccTouchesBegan:withEvent:":
case "ccTouchesMoved:withEvent:":
case "ccTouchesEnded:withEvent:":
case "ccTouchesCancelled:withEvent:":
return type.Name == "CCLayer";
}
return base.Skip (type, selectorName);
}
}
}
108 changes: 108 additions & 0 deletions cocos2d/binding-test/BindingSignatureTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2013 Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Reflection;

using NUnit.Framework;
using TouchUnit.Bindings;

using MonoTouch.Cocos2D;

namespace Cocos2D.Bindings {

[TestFixture]
public class BindingSignatureTest : ApiSignatureTest {

public BindingSignatureTest ()
{
// Useful to know what was being tried if things crash
//LogProgress = true;

// Useful for fixing several errors before rebuilding the bindings
//ContinueOnFailure = true;
}

protected override Assembly Assembly {
get { return typeof (CCAccelAmplitude).Assembly; }
}

protected override bool Skip (Type type, MethodInfo method, string selector)
{
switch (type.Name) {
case "CCMenu":
switch (selector) {
case "alignItemsInColumns:": // "vaList: (va_list) args" is not detectable from the signature
case "alignItemsInRows:": // same as above
return true;
}
break;
case "CCTextureAtlas":
switch (selector) {
case "setQuads:": // ref is used (autogenerated) because of the structure (stret)
return true;
}
break;
}
return base.Skip (type, method, selector);
}

protected override bool IsValidStruct (Type type, string structName)
{
switch (structName) {
case "ccArray":
return type.Name == "CCArray";
case "_ccBezierConfig":
return type.Name == "CCBezierConfig";
case "_ccBlendFunc":
return type.Name == "CCBlendFunc";
case "_ccColor3B":
return type.Name == "CCColor3B";
case "ccColor4F":
return type.Name == "CCColor4F";
case "_ccGridSize": // =ii
return type.Name == "Size" || type.Name == "Point";
case "sCCParticle":
return type.Name == "CCParticle";
case "_ccQuad3":
return type.Name == "CCQuad3";
case "_ccVertex3F": // =fff
return type.Name == "Vector3";
case "_ccV2F_C4B_T2F":
return type.Name == "CCV2F_C4B_T2F";
case "_ccV3F_C4B_T2F_Quad":
return type.Name == "CCV3F_C4B_T2F_Quad";
default:
return base.IsValidStruct (type, structName);
}
}

protected override bool Check (char encodedType, Type type)
{
switch (encodedType) {
// allow signed integer in place of unsigned integer (not to break existing API / code)
case 'I':
if (type.FullName == "System.Int32")
return true;
break;
}
return base.Check (encodedType, type);
}
}
}
26 changes: 26 additions & 0 deletions cocos2d/binding-test/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>3.2</string>
</dict>
</plist>
5 changes: 5 additions & 0 deletions cocos2d/binding-test/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The files Api*Test.cs are located in the maccore repository.
https://github.com/mono/maccore

This project should pick them up automagically if the maccore repository is cloned side-by-side with the
monotouch-bindings repository. Otherwise you'll have to adjust the path to those files to run the tests.
49 changes: 49 additions & 0 deletions cocos2d/binding-test/UnitTestAppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2013 Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Reflection;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.NUnit.UI;

namespace bindingtest {

[Register ("UnitTestAppDelegate")]
public partial class UnitTestAppDelegate : UIApplicationDelegate {
UIWindow window;
TouchRunner runner;

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
runner = new TouchRunner (window);
runner.Add (Assembly.GetExecutingAssembly ());
window.RootViewController = new UINavigationController (runner.GetViewController ());
window.MakeKeyAndVisible ();
return true;
}

static void Main (string[] args)
{
UIApplication.Main (args, null, "UnitTestAppDelegate");
}
}
}
Loading

0 comments on commit 2205a37

Please sign in to comment.