Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ LICENSE text eol=lf

# Super-long text files
C7/c7-static-map-save.json binary
C7/c7-static-map-save.json -diff
EngineTests/data/** binary
C7/c7-static-map-save.json -diff
27 changes: 27 additions & 0 deletions .github/workflows/test-c7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run C7 Tests

on: [push]

jobs:
Run-Tests:
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:6.0

steps:
- name: Checkout
uses: actions/checkout@v2
with:
lfs: false

- name: Install Mono
run: >
apt-get update -y;
apt-get install dirmngr gnupg apt-transport-https ca-certificates software-properties-common -y;
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;
apt-add-repository 'deb https://download.mono-project.com/repo/ubuntu stable-focal main' -y;
apt install mono-complete -y;

- name: Run Tests
run: |
./do test
4 changes: 2 additions & 2 deletions C7Engine/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ private static SaveFileFormat getFileFormat(string path)
}

// Load and initialize a save
public static C7SaveFormat LoadSave(string path, string bicPath)
public static C7SaveFormat LoadSave(string path, string bicPath = "")
{
C7SaveFormat save = null;
C7SaveFormat save;
switch (getFileFormat(path))
{
case SaveFileFormat.Sav:
Expand Down
1 change: 1 addition & 0 deletions C7GameData/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Tile
[JsonIgnore]
public Resource Resource { get; set; }

[JsonIgnore]
public Dictionary<TileDirection, Tile> neighbors { get; set; } = new Dictionary<TileDirection, Tile>();

//See discussion on page 4 of the "Babylon" thread (https://forums.civfanatics.com/threads/0-1-babylon-progress-thread.673959) about sub-terrain type and Civ3 properties.
Expand Down
69 changes: 69 additions & 0 deletions EngineTests/SaveManagerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using C7Engine;
using C7GameData;
using Xunit;

namespace EngineTests {

public class SaveManagerTest {

private readonly string jsonSavePath = Utils.DataPath + "save.json";
private readonly string zipSavePath = Utils.DataPath + "save.zip";
private readonly string invalidTypeSavePath = Utils.DataPath + "save.foo";
private readonly string nonexistentSavePath = Utils.DataPath + "save.nonexistent";
// private readonly string savSavePath = Utils.DataPath + "save.sav";

[Fact]
public void SaveManager_LoadsJsonSaveSuccessfully() {
C7SaveFormat save = null;
Exception ex = Record.Exception(() => save = SaveManager.LoadSave(jsonSavePath));

Assert.Null(ex);
Assert.NotNull(save);
Assert.Equal("test-version-string", save.Version);
Assert.Null(save.Rules);
Assert.Equal(80, save.GameData.map.numTilesTall);
Assert.Equal(3200, save.GameData.map.tiles.Count);
Assert.Equal(14, save.GameData.terrainTypes.Count);
}

[Fact]
public void SaveManager_LoadsZipSaveSuccessfully() {
C7SaveFormat save = null;
Exception ex = Record.Exception(() => save = SaveManager.LoadSave(zipSavePath));

Assert.Null(ex);
Assert.NotNull(save);
Assert.Equal("test-version-string", save.Version);
Assert.Null(save.Rules);
Assert.Equal(80, save.GameData.map.numTilesTall);
Assert.Equal(3200, save.GameData.map.tiles.Count);
Assert.Equal(14, save.GameData.terrainTypes.Count);
}

[Fact]
public void SaveManager_ExceptionOnInvalidFileType() {
C7SaveFormat save1 = null;
Exception ex1 = Record.Exception(() => save1 = SaveManager.LoadSave(invalidTypeSavePath));

Assert.NotNull(ex1);
Assert.Null(save1);

C7SaveFormat save2 = null;
Exception ex2 = Record.Exception(() => save2 = SaveManager.LoadSave(Utils.DataPath));

Assert.NotNull(ex2);
Assert.Null(save2);
}

[Fact]
public void SaveManager_ExceptionOnNonexistentFile() {
C7SaveFormat save = null;
Exception ex = Record.Exception(() => save = SaveManager.LoadSave(nonexistentSavePath));

Assert.Null(save);
Assert.NotNull(ex);
}

}
}
20 changes: 20 additions & 0 deletions EngineTests/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace EngineTests {

using System.IO;
using System.Runtime.CompilerServices;

static class Utils {

public static string DataPath;

private static string ThisFilePath([CallerFilePath] string path = null) {
return path;
}

static Utils() {
DataPath = Path.Combine(Path.GetDirectoryName(ThisFilePath()), "data/");
}

}

}
Empty file added EngineTests/data/save.foo
Empty file.
Loading