Skip to content

Commit

Permalink
CATTY-446 Parse multiple scenes
Browse files Browse the repository at this point in the history
Fixed remaining test cases.
  • Loading branch information
lucatp committed Aug 31, 2023
1 parent 97f28ba commit e02b2fa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ extension UIViewController {
}

@objc func openProject(_ project: Project) {
guard let viewController = storyboard?.instantiateViewController(withIdentifier: "SceneTableViewController")
as? SceneTableViewController, let scene = project.scenes[0] as? Scene else { return }
guard let viewController = self.instantiateViewController("SceneTableViewController") as? SceneTableViewController else { return }

guard let scene = project.scenes[0] as? Scene else { return }
viewController.scene = scene
project.setAsLastUsedProject()
self.navigationController?.pushViewController(viewController, animated: true)
Expand Down
37 changes: 15 additions & 22 deletions src/CattyTests/DataModel/UserDataContainerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,32 +353,25 @@ final class UserDataContainerTest: XCTestCase {
}

func testMutableCopy() {
let list = UserList(name: "testList")
let variable = UserVariable(name: "testvariable")

container.add(list)
container.add(variable)
let list = UserList(name: "testList")
let variable = UserVariable(name: "testvariable")

let copyContainer = container.mutableCopy() as! UserDataContainer
let copyProject = Project()
copyProject.scenes[0] = Scene()
(copyProject.scenes[0] as! Scene).add(object: objectA)
(copyProject.scenes[0] as! Scene).add(object: objectB)
copyProject.userData = copyContainer
container.add(list)
container.add(variable)

XCTAssertTrue(container.isEqual(copyContainer))
XCTAssertFalse(container === copyContainer)
let copyContainer = container.mutableCopy(with: CBMutableCopyContext()) as! UserDataContainer
XCTAssertFalse(container === copyContainer)

let copiedVariables = copyContainer.variables()
XCTAssertEqual(1, copiedVariables.count)
XCTAssertEqual(variable, copiedVariables[0])
XCTAssertTrue(copiedVariables[0] === variable)
let copiedVariables = copyContainer.variables()
XCTAssertEqual(1, copiedVariables.count)
XCTAssertEqual(variable, copiedVariables[0])
XCTAssertTrue(copiedVariables[0] === variable)

let copiedLists = copyContainer.lists()
XCTAssertEqual(1, copiedLists.count)
XCTAssertEqual(list, copiedLists[0])
XCTAssertTrue(copiedLists[0] === list)
}
let copiedLists = copyContainer.lists()
XCTAssertEqual(1, copiedLists.count)
XCTAssertEqual(list, copiedLists[0])
XCTAssertTrue(copiedLists[0] === list)
}

func testMutableCopyWithUpdatedReferences() {
let context = CBMutableCopyContext()
Expand Down
4 changes: 2 additions & 2 deletions src/CattyTests/FileManager/ProjectManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ final class ProjectManagerTests: XCTestCase {
let object3 = SpriteObject()
object3.name = "testObject3"
scene.add(object: object3)
project.scene = scene
project.scenes[0] = scene

XCTAssertEqual(3, scene.objects().count)

projectManager.removeObjects(project, objects: [object1, object2])

XCTAssertEqual(1, project.scene.objects().count)
XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count)
XCTAssertEqual(object3, scene.objects()[0])
}
}
37 changes: 18 additions & 19 deletions src/CattyTests/XML/Serializer/XMLSerializerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,28 @@ final class XMLSerializerTests: XMLAbstractTest {
}

func testFormulaAndMoveNStepsBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993")
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993")
let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 5) as! MoveNStepsBrick

let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[6]"
let equal = self.isXMLElement(xmlElement: brick.xmlElement(with: nil), equalToXMLElementForXPath: xmlElementPath, inProjectForXML: "ValidProjectAllBricks0991")
let xmlElementPath = "//program/scenes/scene/objectList/object[1]/scriptList/script[1]/brickList/brick[6]"
let equal = self.isXMLElement(xmlElement: brick.xmlElement(with: nil), equalToXMLElementForXPath: xmlElementPath, inProjectForXML: "ValidProjectAllBricks0994")
XCTAssertTrue(equal, "XMLElement invalid!")
}

func testRemoveObjectAndSerializeProject() {
let projectName = "ValidProjectAllBricks09993"
let referenceProject = self.getProjectForXML(xmlFile: projectName)
let project = self.getProjectForXML(xmlFile: projectName)
XCTAssertEqual(1, project.scenes.count)
let moleOne = (project.scenes[0] as! Scene).object(at: 1)!
(project.scenes[0] as! Scene).removeObject(moleOne)

XCTAssertTrue((project.scenes[0] as! Scene).objects().count > 1)

let firstObject = (project.scenes[0] as! Scene).object(at: 1)!
(project.scenes[0] as! Scene).removeObject(firstObject)

let serializerContext = CBXMLSerializerContext(project: project)

let xmlElement = project.xmlElement(with: serializerContext)
XCTAssertNotNil(xmlElement, "Error during serialization of removed object")
XCTAssertEqual((project.scenes[0] as! Scene).objects().count + 1,
(referenceProject.scenes[0] as! Scene).objects().count,
"Object not properly removed")
XCTAssertEqual((project.scenes[0] as! Scene).objects().count + 1, (referenceProject.scenes[0] as! Scene).objects().count, "Object not properly removed")
XCTAssertFalse((referenceProject.xmlElement(with: CBXMLSerializerContext(project: Project())).isEqual(to: xmlElement)), "Object not properly removed")

let parserContext = CBXMLParserContext(languageVersion: CGFloat(Float32(0.9993)), andRootElement: xmlElement)
Expand Down Expand Up @@ -99,7 +98,7 @@ final class XMLSerializerTests: XMLAbstractTest {
func testPenDownBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993")

let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 41) as! PenDownBrick
let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 42) as! PenDownBrick
let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[42]"

guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else {
Expand All @@ -113,7 +112,7 @@ final class XMLSerializerTests: XMLAbstractTest {
func testPenUpBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993")

let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 42) as! PenUpBrick
let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 43) as! PenUpBrick
let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[43]"

guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else {
Expand All @@ -127,7 +126,7 @@ final class XMLSerializerTests: XMLAbstractTest {
func testPenClearBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993")

let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 43) as! PenClearBrick
let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 44) as! PenClearBrick
let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[44]"

guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else {
Expand All @@ -141,7 +140,7 @@ final class XMLSerializerTests: XMLAbstractTest {
func testSetPenSizeBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993")

let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 44) as! SetPenSizeBrick
let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 45) as! SetPenSizeBrick
let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[45]"

guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else {
Expand All @@ -155,8 +154,8 @@ final class XMLSerializerTests: XMLAbstractTest {
func testSetPenColorBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993")

let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 45) as! SetPenColorBrick
let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[46]"
let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! SetPenColorBrick
let xmlElementPath = "//program/scenes/scene/objectList/object[1]/scriptList/script[1]/brickList/brick[47]"

guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: project)) else {
XCTFail("xmlElement is nil")
Expand All @@ -170,7 +169,7 @@ final class XMLSerializerTests: XMLAbstractTest {
func testStampBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993")

let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! StampBrick
let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 47) as! StampBrick
let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[47]"

guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else {
Expand All @@ -184,8 +183,8 @@ final class XMLSerializerTests: XMLAbstractTest {
func testAddItemToUserListBrick() {
let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993")

let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 0) as! AddItemToUserListBrick
let xmlElementPath = "//program/scenes/scene[1]/objectList/object[1]/scriptList/script[1]/brickList/brick[1]"
let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 48) as! AddItemToUserListBrick
let xmlElementPath = "//program/scenes/scene[1]/objectList/object[1]/scriptList/script[1]/brickList/brick[49]"

guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: project)) else {
XCTFail("xmlElement is nil")
Expand Down

0 comments on commit e02b2fa

Please sign in to comment.