Skip to content

Commit

Permalink
CATTY-446
Browse files Browse the repository at this point in the history
Fixed some testcases
  • Loading branch information
mt1622 committed Aug 31, 2023
1 parent 26f0b77 commit 97f28ba
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "4e9bbf2808b8fee444e84a48f5f3c12641987d3e",
"version" : "1.7.2"
"revision" : "bc6a19702ac76ac4e488b68148710eb815f9bc56",
"version" : "1.7.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/Catty/IO/ProjectManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
}

@objc func removeObjects(_ project: Project, objects: [SpriteObject]) {
let scene = project.scene
guard let scene = project.scenes[0] as? Scene else {return}
for object in objects where scene.objects().contains(object) {
scene.removeObject(object)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ extension StagePresenterViewController {
func shareDST(embroideryService: EmbroideryProtocol) {

var embroideryStream = [EmbroideryStream]()
for object in project.scene.objects() where !object.spriteNode.embroideryStream.isEmpty {

guard let scene = project.scenes[0] as? Scene else {return}
for object in scene.objects() where !object.spriteNode.embroideryStream.isEmpty {
embroideryStream.append(object.spriteNode.embroideryStream)
}
let embroideryStreamMerged = EmbroideryStream(streams: embroideryStream)
Expand Down
5 changes: 3 additions & 2 deletions src/CattyTests/Bricks/SetBackgroundByIndexBrickTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ final class SetBackgroundByIndexBrickTest: XCTestCase {

override func setUp() {
project = ProjectManager.shared.createProject(name: "setBackgroundByIndexTest", projectId: "1")
spriteObject = project.scene.object(at: 0)
spriteObject.scene = project.scene
spriteObject = (project.scenes[0] as! Scene).object(at: 0)
//guard let scene = project.scenes[0] as? Scene else {XCTFail("No scene found."); return}
spriteObject.scene = project.scenes[0] as? Scene
spriteObject.name = "SpriteObjectName"

spriteNode = CBSpriteNode(spriteObject: spriteObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class TouchesEdgeSensorTest: XMLAbstractTest {
let filePath = Bundle(for: type(of: self)).path(forResource: "test.png", ofType: nil)!

let look = LookMock(name: "look", absolutePath: filePath)
project.scene.object(at: 1)?.lookList = [look]
(project.scenes[0] as! Scene).object(at: 1)?.lookList = [look]

let screenHeight = Double(project.header.screenHeight as! Int / 2)
let screenWidth = Double(project.header.screenHeight as! Int / 2)
Expand All @@ -65,37 +65,37 @@ final class TouchesEdgeSensorTest: XMLAbstractTest {
let started = stage.startProject()

XCTAssertTrue(started)
XCTAssertEqual(project.scene.objects().count, 2)
XCTAssertEqual((project.scenes[0] as! Scene).objects().count, 2)

//no edge touch
expect(touchEdgeVar?.value as? Int).toEventually(equal(0), timeout: .seconds(5))
XCTAssertEqual(sensor.rawValue(for: project.scene.object(at: 1)!), 0)
XCTAssertEqual(sensor.rawValue(for: (project.scenes[0] as! Scene).object(at: 1)!), 0)

//right edge touch
project.scene.object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: screenWidth / 2, y: 0)
(project.scenes[0] as! Scene).object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: screenWidth / 2, y: 0)
expect(touchEdgeVar?.value as? Int).toEventually(equal(1), timeout: .seconds(5))
XCTAssertEqual(sensor.rawValue(for: project.scene.object(at: 1)!), 1)
XCTAssertEqual(sensor.rawValue(for: (project.scenes[0] as! Scene).object(at: 1)!), 1)

//left edge touch
project.scene.object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: -screenWidth / 2, y: 0)
(project.scenes[0] as! Scene).object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: -screenWidth / 2, y: 0)
expect(touchEdgeVar?.value as? Int).toEventually(equal(1), timeout: .seconds(5))
XCTAssertEqual(sensor.rawValue(for: project.scene.object(at: 1)!), 1)
XCTAssertEqual(sensor.rawValue(for: (project.scenes[0] as! Scene).object(at: 1)!), 1)

//top edge touch
project.scene.object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: 0, y: screenHeight / 2)
(project.scenes[0] as! Scene).object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: 0, y: screenHeight / 2)
expect(touchEdgeVar?.value as? Int).toEventually(equal(1), timeout: .seconds(5))
XCTAssertEqual(sensor.rawValue(for: project.scene.object(at: 1)!), 1)
XCTAssertEqual(sensor.rawValue(for: (project.scenes[0] as! Scene).object(at: 1)!), 1)

//bottom edge touch
project.scene.object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: 0, y: -screenHeight / 2)
(project.scenes[0] as! Scene).object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: 0, y: -screenHeight / 2)
expect(touchEdgeVar?.value as? Int).toEventually(equal(1), timeout: .seconds(5))
XCTAssertEqual(sensor.rawValue(for: project.scene.object(at: 1)!), 1)
XCTAssertEqual(sensor.rawValue(for: (project.scenes[0] as! Scene).object(at: 1)!), 1)

//hidden spriteNode
project.scene.object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: 0, y: -screenHeight / 2)
project.scene.object(at: 1)?.spriteNode.isHidden = true
(project.scenes[0] as! Scene).object(at: 1)?.spriteNode.catrobatPosition = CBPosition(x: 0, y: -screenHeight / 2)
(project.scenes[0] as! Scene).object(at: 1)?.spriteNode.isHidden = true
expect(touchEdgeVar?.value as? Int).toEventually(equal(1), timeout: .seconds(5))
XCTAssertEqual(sensor.rawValue(for: project.scene.object(at: 1)!), 1)
XCTAssertEqual(sensor.rawValue(for: (project.scenes[0] as! Scene).object(at: 1)!), 1)
}

func testConvertToStandarized() {
Expand Down
12 changes: 6 additions & 6 deletions src/CattyTests/Utils/UtilTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ final class UtilTests: XCTestCase {

func testdefaultSceneNameForSceneNumber() {
var sceneDirectoryname = Util.defaultSceneName(forSceneNumber: 1)
XCTAssertEqual(sceneDirectoryname, "Scene 1")
XCTAssertEqual(sceneDirectoryname, "\(kLocalizedScene) 1")

sceneDirectoryname = Util.defaultSceneName(forSceneNumber: 99)
XCTAssertEqual(sceneDirectoryname, "Scene 99")
XCTAssertEqual(sceneDirectoryname, "\(kLocalizedScene) 99")
}

func testAppName() {
Expand Down Expand Up @@ -226,7 +226,7 @@ final class UtilTests: XCTestCase {
func testLookWithNameForObject() {
let look = Look(name: "TestLook", filePath: "/test/path")
spriteObject = SpriteObject()
project.scene.add(object: spriteObject!)
(project.scenes[0] as! Scene).add(object: spriteObject!)
spriteObject.lookList.add(look)

let utilLook = Util.look(with: "TestLook", for: spriteObject)
Expand All @@ -237,17 +237,17 @@ final class UtilTests: XCTestCase {
func testObjectWithNameForScene() {
spriteObject = SpriteObject()
spriteObject.name = "TestSpriteObject"
project.scene.add(object: spriteObject!)
(project.scenes[0] as! Scene).add(object: spriteObject!)

let utilSpriteObject = Util.object(with: "TestSpriteObject", for: project.scene)
let utilSpriteObject = Util.object(with: "TestSpriteObject", for: (project.scenes[0] as! Scene))

XCTAssertEqual(utilSpriteObject, spriteObject)
}

func testSoundWithNameForObject() {
let sound = Sound(name: "TestSound", fileName: "/test/path")
spriteObject = SpriteObject()
project.scene.add(object: spriteObject!)
(project.scenes[0] as! Scene).add(object: spriteObject!)
spriteObject.soundList.add(sound)

let utilSound = Util.sound(with: "TestSound", for: spriteObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ final class StagePresenterViewControllerTest: XCTestCase {
let backgroundNode = CBSpriteNodeMock(spriteObject: background)
background.spriteNode = backgroundNode

let object = SpriteObjectMock(scene: project.scene)
let object = SpriteObjectMock(scene: (project.scenes[0] as! Scene))
let objectNode = CBSpriteNodeMock(spriteObject: object)
objectNode.embroideryStream = stream
object.spriteNode = objectNode
project.scene.add(object: object)
(project.scenes[0] as? Scene)?.add(object: object)

XCTAssertEqual(2, project.allObjects().count)
XCTAssertNil(vc.latestPresentedViewController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class XMLParserTests0992: XMLAbstractTest {

func testSetTempoToBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0992")
let setTempoToBrick = (project.scene.object(at: 1)!.scriptList.object(at: 0) as! Script).brickList.object(at: 5) as! Brick
let setTempoToBrick = ((project.scenes[0] as! Scene).object(at: 1)!.scriptList.object(at: 0) as! Script).brickList.object(at: 5) as! Brick

XCTAssertTrue(setTempoToBrick.isKind(of: SetTempoToBrick.self), "Invalid brick type")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ class XMLParserTests0993: XMLAbstractTest {
func testJoinThreeFunction() {
let project = self.getProjectForXML(xmlFile: "Functions_0993")

XCTAssertEqual(4, project.scene.objects().count, "Invalid object list")
XCTAssertEqual(4, (project.scenes[0] as! Scene).objects().count, "Invalid object list")

let object = project.scene.object(at: 2)!
let object = (project.scenes[0] as! Scene).object(at: 2)!
XCTAssertEqual(1, object.scriptList.count, "Invalid script list")

let script = object.scriptList.object(at: 0) as! Script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class XMLParserTests0994: XMLAbstractTest {

func testSetPenColorBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0994")
let setPenColorBrick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! Brick
let setPenColorBrick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! Brick

XCTAssertEqual(0, project.unsupportedElements.count)
XCTAssertTrue(setPenColorBrick.isKind(of: SetPenColorBrick.self), "Invalid brick type")
Expand All @@ -58,7 +58,7 @@ class XMLParserTests0994: XMLAbstractTest {

func testGlideToBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0994")
let glideToBrick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 10) as! Brick
let glideToBrick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 10) as! Brick

XCTAssertEqual(0, project.unsupportedElements.count)
XCTAssertTrue(glideToBrick.isKind(of: GlideToBrick.self), "Invalid brick type")
Expand All @@ -71,7 +71,7 @@ class XMLParserTests0994: XMLAbstractTest {

func testThinkForBubbleBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0994")
let thinkForBubbleBrick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 37) as! Brick
let thinkForBubbleBrick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 37) as! Brick

XCTAssertEqual(0, project.unsupportedElements.count)
XCTAssertTrue(thinkForBubbleBrick.isKind(of: ThinkForBubbleBrick.self), "Invalid brick type")
Expand All @@ -83,7 +83,7 @@ class XMLParserTests0994: XMLAbstractTest {

func testSayForBubbleBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0994")
let sayForBubbleBrick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 36) as! Brick
let sayForBubbleBrick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 36) as! Brick

XCTAssertEqual(0, project.unsupportedElements.count)
XCTAssertTrue(sayForBubbleBrick.isKind(of: SayForBubbleBrick.self), "Invalid brick type")
Expand All @@ -96,10 +96,10 @@ class XMLParserTests0994: XMLAbstractTest {
func testSoundList() {
let project = self.getProjectForXML(xmlFile: "Flap_Pac_Man_0994")

var soundList = (project.scene.object(at: 0)!.soundList)!
var soundList = ((project.scenes[0] as! Scene).object(at: 0)!.soundList)!
XCTAssertEqual(0, soundList.count)

soundList = (project.scene.object(at: 1)!.soundList)!
soundList = ((project.scenes[0] as! Scene).object(at: 1)!.soundList)!
XCTAssertEqual(2, soundList.count)

var sound = soundList.object(at: 0) as! Sound
Expand All @@ -112,7 +112,7 @@ class XMLParserTests0994: XMLAbstractTest {
XCTAssertEqual(sound.name, "Evo2MinusScore2", "Wrong Sound name")
XCTAssertEqual(sound.fileName, "cb61b2020b42d8b6276bb374dda290e2_Evo2MinusScore2.wav", "Wrong Sound fileName")

let playSoundBrick = (project.scene.object(at: 1)!.scriptList.object(at: 1) as! Script).brickList.object(at: 14) as! PlaySoundBrick
let playSoundBrick = ((project.scenes[0] as! Scene).object(at: 1)!.scriptList.object(at: 1) as! Script).brickList.object(at: 14) as! PlaySoundBrick
XCTAssertTrue(playSoundBrick.sound.isEqual(sound), "Invalid Sound reference")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class XMLParserTests0995: XMLAbstractTest {

func testSetPenColorBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0995")
let setPenColorBrick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! Brick
let setPenColorBrick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! Brick

XCTAssertEqual(0, project.unsupportedElements.count)
XCTAssertTrue(setPenColorBrick.isKind(of: SetPenColorBrick.self), "Invalid brick type")
Expand All @@ -63,7 +63,7 @@ class XMLParserTests0995: XMLAbstractTest {

func testGlideToBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0995")
let glideToBrick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 10) as! Brick
let glideToBrick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 10) as! Brick

XCTAssertEqual(0, project.unsupportedElements.count)
XCTAssertTrue(glideToBrick.isKind(of: GlideToBrick.self), "Invalid brick type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class XMLParserTests0996: XMLAbstractTest {

func testSetPenColorBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0996")
let setPenColorBrick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! Brick
let setPenColorBrick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! Brick

XCTAssertEqual(0, project.unsupportedElements.count)
XCTAssertTrue(setPenColorBrick.isKind(of: SetPenColorBrick.self), "Invalid brick type")
Expand All @@ -62,7 +62,7 @@ class XMLParserTests0996: XMLAbstractTest {

func testGlideToBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0996")
let glideToBrick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 10) as! Brick
let glideToBrick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 10) as! Brick

XCTAssertEqual(0, project.unsupportedElements.count)
XCTAssertTrue(glideToBrick.isKind(of: GlideToBrick.self), "Invalid brick type")
Expand All @@ -75,7 +75,7 @@ class XMLParserTests0996: XMLAbstractTest {

func testParseLookAndLooklist() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0996")
let looklist = project.scene.object(at: 0)!.lookList
let looklist = (project.scenes[0] as! Scene).object(at: 0)!.lookList
XCTAssertEqual(1, looklist!.count)

let look = (looklist?.object(at: 0)) as! Look
Expand All @@ -85,7 +85,7 @@ class XMLParserTests0996: XMLAbstractTest {

func testParseSoundAndSoundlist() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0996")
let soundlist = ((project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 9) as! PointToBrick).pointedObject.soundList
let soundlist = (((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 9) as! PointToBrick).pointedObject.soundList
XCTAssertEqual(1, soundlist!.count)

let sound = (soundlist?.object(at: 0)) as! Sound
Expand All @@ -95,17 +95,17 @@ class XMLParserTests0996: XMLAbstractTest {

func testParseLocalLists() {
let project = self.getProjectForXML(xmlFile: "UserLists_0996")
let objects = project.scene.objects()
let objects = (project.scenes[0] as! Scene).objects()
XCTAssertEqual(3, objects.count)

let backgroundObject = project.scene.object(at: 0)
let backgroundObject = (project.scenes[0] as! Scene).object(at: 0)
XCTAssertEqual("Background", backgroundObject?.name)

let localLists = backgroundObject?.userData.lists()
XCTAssertEqual(1, localLists?.count)
XCTAssertEqual("localListBackground", localLists?[0].name)

let object = project.scene.object(at: 1)
let object = (project.scenes[0] as! Scene).object(at: 1)
XCTAssertEqual("Object1", object?.name)

let localListsObject = object?.userData.lists()
Expand Down
Loading

0 comments on commit 97f28ba

Please sign in to comment.