Exemplo n.º 1
0
    public void BindTest()
    {
        EventHolder holder  = new EventHolder();
        EventCall   call    = new EventCall();
        var         handle1 = call.Bind(holder);

        //イベント
        Assert.IsTrue(call.Message(TestEvent.Event1));
        Assert.AreEqual(holder.value, "event1");
        //型が違う
        Assert.IsFalse(call.Message(TestEvent.Event1, "test"));
        Assert.AreNotEqual(holder.value, "test");
        //イベントを発火
        Assert.IsTrue(call.Message(TestEvent.Event2, "event2"));
        Assert.AreEqual(holder.value, "event2");

        //再びバインドするため二回イベント呼ばれる
        call.Bind(holder);
        holder.value = "";
        Assert.IsTrue(call.Broadcast(TestEvent.Event3, 123));
        Assert.AreEqual(holder.value, "123123");

        //一つ目のバインドを解除するので一回だけ呼ばれる
        handle1.Dispose();
        holder.value = "";
        Assert.IsTrue(call.Broadcast(TestEvent.Event3, 123));
        Assert.AreEqual(holder.value, "123");
    }
Exemplo n.º 2
0
    public void Test1()
    {
        Init();
        bool ret          = false;
        var  stateMachine = StateMachineProvider <AutoStateBase> .Create(null);

        //2に遷移
        Check(0, 1, 0, 0);
        ret = stateMachine.StrictTransition(StateEvent.Event2);
        //直接遷移は基本的に同じステートには遷移しない
        Check(0, 1, 0, 0);
        Assert.IsFalse(ret);
        ret = stateMachine.StrictTransition(StateEvent.Event3);
        //ステート3に遷移する
        Check(0, 1, 1, 0);
        Assert.IsTrue(ret);
        stateMachine.Transition(StateEvent.Event3);
        //再遷移フラグを付けた場合可能になる
        Check(0, 1, 2, 0);
        stateMachine.Transition(StateEvent.Event1);
        //ステート1に遷移する
        Check(1, 1, 2, 0);
        //存在しないイベントを発行
        ret = stateMachine.StrictTransition(StateEvent.Event5);
        Assert.IsFalse(ret);
    }
Exemplo n.º 3
0
    public IEnumerator OnRepositoryLoad_OnRepositoryDirtyShouldCallRepositoryLoad_OnRepositoryLoadCalled()
    {
        Assert.IsFalse(gitManager.IsUpdating);
        gitManager.MarkDirty(true);
        yield return(null);

        Assert.AreEqual(1, onRepositoryLoadedCalled);
    }
Exemplo n.º 4
0
    public void ProcessText_EscapedBracePair()
    {
        const string input = "&obrc;stuff&cbrc;";
        StructList <TextExpression> output = new StructList <TextExpression>();

        TextTemplateProcessor.ProcessTextExpressions(input, output);
        Assert.AreEqual(1, output.size);
        Assert.AreEqual("{stuff}", output[0].text);
        Assert.IsFalse(output[0].isExpression);
    }
Exemplo n.º 5
0
    public IEnumerator AsyncTest2()
    {
        bool complete = false;
        var  action   = Trigger.From(_AsyncTest2(() => complete = true));

        Assert.IsFalse(complete);
        yield return(action);

        Assert.IsTrue(complete);
    }
Exemplo n.º 6
0
    public IEnumerator AsyncTest1()
    {
        var action = Trigger.From(_AsyncTest1());

        yield return(new WaitForSeconds(0.1f));

        Assert.IsFalse(action.Fired);
        yield return(action);

        Assert.IsTrue(action.Fired);
    }
Exemplo n.º 7
0
    public IEnumerator ModalTest2()
    {
        using (var tester = new Tester())
        {
            BootParam prm     = new BootParam();
            var       counter = new Counter();
            prm.BootContents.Add(new MainTestParam {
                Counter = counter
            });
            yield return(WrapTask(tester.Controller.Boot(prm)));


            var content  = tester.Controller.Get <MainTestContent>();
            var modalRet = content.RunModal(() => true);

            Exception error = null;
            bool      ret   = false;
            try
            {
                content.Append <SubContent1>(new SubParam1
                {
                    Counter = counter
                }).ContinueWith(x => ret = true);
            }
            catch (Exception ex)
            {
                error = ex;
            }
            //モーダル中の追加はエラーになる
            Assert.IsNotNull(error);
            Assert.IsFalse(ret);

            error = null;

            try
            {
                content.Switch <SubContent1>(new SubParam1
                {
                    Counter = counter
                }).ContinueWith(x => ret = true);
            }
            catch (Exception ex)
            {
                error = ex;
            }
            //モーダル中の変更はエラーになる
            Assert.IsNotNull(error);
            Assert.IsFalse(ret);

            yield return(WrapTask(modalRet));

            Assert.AreEqual(true, modalRet.Result);
        }
    }
Exemplo n.º 8
0
 public void Test3()
 {
     //キーを変えれば共存できる
     using (var ctx4 = new Context("Test4"))
         using (var ctx5 = new Context("Test5"))
         {
             ctx4.Save.Set(SaveKey.Bool, true);
             ctx4.Save.Save();
             Assert.IsFalse(ctx5.Save.GetBool(SaveKey.Bool));
         }
 }
Exemplo n.º 9
0
    public void ProcessText_ExpressionWithNestedBraces()
    {
        const string input = "\n\n\n\n{some expression{}}";
        StructList <TextExpression> output = new StructList <TextExpression>();

        TextTemplateProcessor.ProcessTextExpressions(input, output);
        Assert.AreEqual(2, output.size);
        Assert.AreEqual("\n\n\n\n", output[0].text);
        Assert.IsFalse(output[0].isExpression);
        Assert.AreEqual("some expression{}", output[1].text);
        Assert.IsTrue(output[1].isExpression);
    }
Exemplo n.º 10
0
    private IEnumerator TryToLoadUrl(string url)
    {
        yield return(new WaitForEndOfFrame());

        var www = UnityWebRequest.Get(url);

        yield return(www.SendWebRequest());

        Assert.IsFalse(www.isHttpError || www.isNetworkError, www.error);
        Assert.AreEqual(www.responseCode, 200, "Unexpected HTTP response code");
        yield return(new WaitForEndOfFrame());
    }
Exemplo n.º 11
0
    private void Validate(string path)
    {
        var fileName = Path.GetFileName(path);
        var asset    = AssetDatabase.LoadAssetAtPath <QuestAsset>(path);

        Assert.IsNotNull(asset, $"{fileName} => asset is null");

        Assert.IsFalse(string.IsNullOrEmpty(asset.id),
                       $"{fileName} => ID is null or empty");

        Assert.IsFalse(asset.id.IndexOf("A", StringComparison.Ordinal) != 0,
                       $"{fileName} => The naming conventions are different. : {asset.id}");
    }
Exemplo n.º 12
0
    public void ProcessText_MultipleExpressionsMixed()
    {
        const string input = "{hello}hi there{'there'}";
        StructList <TextExpression> output = new StructList <TextExpression>();

        TextTemplateProcessor.ProcessTextExpressions(input, output);
        Assert.AreEqual(3, output.size);
        Assert.AreEqual("hello", output[0].text);
        Assert.AreEqual("hi there", output[1].text);
        Assert.AreEqual("'there'", output[2].text);
        Assert.IsTrue(output[0].isExpression);
        Assert.IsFalse(output[1].isExpression);
        Assert.IsTrue(output[2].isExpression);
    }
Exemplo n.º 13
0
    public IEnumerator TimeTest2()
    {
        var trigger = Trigger.Time(1);
        var val     = "";

        trigger.Add(x => val = "fire");
        yield return(new WaitForSeconds(0.5f));

        Assert.IsFalse(trigger.Fired);
        Assert.AreEqual(val, "");
        yield return(new WaitForSeconds(1.5f));

        Assert.IsTrue(trigger.Fired);
        Assert.AreEqual(val, "fire");
    }
Exemplo n.º 14
0
    public IEnumerator Test5()
    {
        using (var tester = new Tester())
        {
            //ネストしていてもエラーを拾える
            var       routine = tester.Routine(Nest2(true));
            bool      ret     = false;
            Exception ex      = null;
            routine.Observe((x, y) => { ret = x; ex = y; });
            yield return(routine);

            Assert.IsFalse(ret);
            Assert.IsNotNull(ex);
            Assert.IsTrue(!routine.IsRunning);
        }
    }
Exemplo n.º 15
0
    public IEnumerator Test3()
    {
        using (var tester = new Tester())
        {
            //エラーのハンドリング
            var       routine = tester.Routine(Error());
            bool      ret     = false;
            Exception ex      = null;
            routine.Observe((x, y) => { ret = x; ex = y; });
            yield return(routine);

            Assert.IsFalse(ret);
            Assert.IsNotNull(ex);
            Assert.IsTrue(!routine.IsRunning);
        }
    }
Exemplo n.º 16
0
    public IEnumerator TimeTest3()
    {
        Trigger <string> trigger = new Trigger <string>();
        var action = trigger.Time(2f);
        var val    = "";

        action.Add(x => val = x);
        trigger.Fire("fire");
        yield return(new WaitForSeconds(0.5f));

        //まだ発火されない
        Assert.IsFalse(action.Fired);
        //トリガーを待つ
        yield return(action);

        Assert.IsTrue(trigger.Fired);
        Assert.AreEqual(val, "fire");
    }
Exemplo n.º 17
0
    private IEnumerator VerifyCompressionSupport(string url)
    {
        yield return(new WaitForEndOfFrame());

        var www = UnityWebRequest.Get(url);

        //var requestEncodings = www.GetRequestHeader("Accept-Encoding").ToLower();
        //Assert.IsTrue(requestEncodings.Contains("gzip"), string.Format("Expected: {0}, Actual: {1}", "gzip", requestEncodings));
        yield return(www.SendWebRequest());

        Assert.IsFalse(www.isHttpError || www.isNetworkError, www.error);
        Assert.AreEqual(www.responseCode, 200, "Unexpected HTTP response code");
        var encoding = www.GetResponseHeader("Content-Encoding").ToLower();

        Assert.IsTrue(encoding.Contains("gzip"), string.Format("Expected: {0}, Actual: {1}", "gzip", encoding));
        Assert.AreEqual(www.responseCode, 200, "Unexpected HTTP response code");
        yield return(new WaitForEndOfFrame());
    }
Exemplo n.º 18
0
    public void Test1()
    {
        //単純な単一パラメータの保存
        using (var ctx = new Context("Test1"))
        {
            Assert.IsFalse(ctx.Save.GetBool(SaveKey.Bool));
            ctx.Save.Set(SaveKey.Bool, true);
            Assert.IsTrue(ctx.Save.GetBool(SaveKey.Bool));

            Assert.AreEqual(ctx.Save.GetString(SaveKey.String, "DefString"), "DefString");
            ctx.Save.Set(SaveKey.String, "TestTest");
            Assert.AreEqual(ctx.Save.GetString(SaveKey.String), "TestTest");

            Assert.AreEqual(ctx.Save.GetInt(SaveKey.Int, 5), 5);
            ctx.Save.Set(SaveKey.Int, 22);
            Assert.AreEqual(ctx.Save.GetInt(SaveKey.Int), 22);

            Assert.AreEqual(ctx.Save.GetFloat(SaveKey.Float, 5.3f), 5.3f);
            ctx.Save.Set(SaveKey.Float, 22.3f);
            Assert.AreEqual(ctx.Save.GetFloat(SaveKey.Float), 22.3f);

            Assert.IsNull(ctx.Save.GetBytes(SaveKey.Bytes));
            var bytes = System.Text.Encoding.UTF8.GetBytes("TTTTTest");
            ctx.Save.Set(SaveKey.Bytes, bytes);
            var getBytes = ctx.Save.GetBytes(SaveKey.Bytes);
            for (int i = 0; i < bytes.Length; i++)
            {
                Assert.AreEqual(bytes[i], getBytes[i]);
            }

            ctx.Save.Save();

            ctx.Save.Delete(SaveKey.Bool);
            Assert.IsFalse(ctx.Save.GetBool(SaveKey.Bool));
            ctx.Save.Set(SaveKey.Bool, true);
            Assert.IsTrue(ctx.Save.GetBool(SaveKey.Bool));

            ctx.Save.DeleteKeys();
            Assert.IsFalse(ctx.Save.GetBool(SaveKey.Bool));
            Assert.IsTrue(string.IsNullOrEmpty(ctx.Save.GetString(SaveKey.String)));
            Assert.AreEqual(ctx.Save.GetInt(SaveKey.Int), 0);
            Assert.AreEqual(ctx.Save.GetFloat(SaveKey.Float), 0);
        }
    }
Exemplo n.º 19
0
    public void MessageTest1()
    {
        EventCall call  = new EventCall();
        int       count = 0;
        var       path  = call.Subscribe(TestEvent.Event1, () => count++);

        //イベントを発行
        Assert.IsTrue(call.Message(TestEvent.Event1));
        Assert.AreEqual(count, 1);
        //イベントを発行
        Assert.IsTrue(call.Message(TestEvent.Event1));
        Assert.AreEqual(count, 2);
        //登録していないイベント
        Assert.IsFalse(call.Message(TestEvent.Event2));
        Assert.AreEqual(count, 2);
        //パスを解除
        path.Dispose();
        Assert.IsFalse(call.Message(TestEvent.Event1));
        Assert.AreEqual(count, 2);
    }
Exemplo n.º 20
0
    public IEnumerator MangedTest()
    {
        using (var tester = new Tester())
        {
            var       counter = new Counter();
            BootParam prm     = new BootParam();
            prm.BootContents.Add(new MainTestParam {
                Counter = counter
            });
            yield return(WrapTask(tester.Controller.Boot(prm)));

            var manded = tester.Controller.Get <IHasManagedHolder>();

            bool dispose = false;
            // disposed時にアクションを発火するように登録
            var action = manded.Manage(() => dispose = true);
            Assert.IsFalse(dispose);
            //Unmanageで解放される
            manded.Unmanage(action);
            Assert.IsTrue(dispose);

            //再登録
            dispose = false;
            manded.Manage(() => dispose = true);
            //非同期を登録
            var asyncDispose = new AsyncDispose();
            manded.ManageAsync(asyncDispose);
            tester.Message(MainTestContent.Event.Switch, counter);

            //直ぐには実行されない
            Assert.IsFalse(asyncDispose.Disposed);

            yield return(counter.Wait("Run", 2));

            yield return(tester.Close());

            Assert.IsTrue(dispose);
            Assert.IsTrue(asyncDispose.Disposed);
        }
    }
Exemplo n.º 21
0
    public void SubCallTest()
    {
        EventCall root  = new EventCall();
        EventCall call1 = root.SubCall();
        EventCall call2 = root.SubCall();
        EventCall call3 = root.SubCall();
        EventCall call4 = call1.SubCall();
        EventCall call5 = call4.SubCall();
        int       ret   = 0;
        var       path1 = call1.Subscribe(TestEvent.Event1, () => ret = 1);

        call2.Subscribe(TestEvent.Event1, () => ret = 2);
        call3.Subscribe(TestEvent.Event1, () => ret = 3);
        call4.Subscribe(TestEvent.Event1, () => ret = 4);
        call5.Subscribe(TestEvent.Event1, () => ret = 5);

        //メッセージが伝播してcall1優先される
        Assert.IsTrue(root.Message(TestEvent.Event1));
        Assert.AreEqual(ret, 1);

        //メッセージが優先される
        Assert.IsTrue(call2.Message(TestEvent.Event1));
        Assert.AreEqual(ret, 2);
        Assert.IsTrue(call3.Message(TestEvent.Event1));
        Assert.AreEqual(ret, 3);

        //パスがなくなったので、サブコールのイベントが呼ばれる
        path1.Dispose();
        Assert.IsTrue(root.Message(TestEvent.Event1));
        Assert.AreEqual(ret, 4);

        //子のサブコールも解放される
        call1.Dispose();
        Assert.IsFalse(call5.Message(TestEvent.Event1));
        Assert.AreEqual(ret, 4);

        Assert.IsTrue(root.Message(TestEvent.Event1));
        Assert.AreEqual(ret, 2);
    }
Exemplo n.º 22
0
    public void MessageTest3()
    {
        EventCall call   = new EventCall();
        int       count1 = 0;
        int       count2 = 0;
        int       count3 = 0;
        var       path1  = call.Subscribe(TestEvent.Event1, () => count1++);
        var       path2  = call.Subscribe(TestEvent.Event1, () => count2++);
        var       path3  = call.Subscribe(TestEvent.Event1, () => count3++);

        //メッセージは一番最初に登録された物が優先される
        for (int i = 0; i < 5; i++)
        {
            Assert.IsTrue(call.Message(TestEvent.Event1));
            Assert.AreEqual(count1, 1 + i);
            Assert.AreEqual(count2, 0);
            Assert.AreEqual(count3, 0);
        }
        //一つ解除する
        path1.Dispose();
        //ブロードキャストは全ての登録イベントに発火する
        for (int i = 0; i < 5; i++)
        {
            Assert.IsTrue(call.Broadcast(TestEvent.Event1));
            Assert.AreEqual(count1, 5);
            Assert.AreEqual(count2, 1 + i);
            Assert.AreEqual(count3, 1 + i);
        }
        path2.Dispose();
        path3.Dispose();
        //全て解除すると発火されない
        for (int i = 0; i < 5; i++)
        {
            Assert.IsFalse(call.Broadcast(TestEvent.Event1));
            Assert.AreEqual(count1, 5);
            Assert.AreEqual(count2, 5);
            Assert.AreEqual(count3, 5);
        }
    }
Exemplo n.º 23
0
    public void Test2()
    {
        //データクラスのセーブ
        using (var ctx = new Context("Test2"))
        {
            TestData data = null;
            for (int i = 0; i < 2; i++)
            {
                ctx.Save.TryGet(out data);
                Assert.IsTrue(string.IsNullOrEmpty(data.TestString));
                Assert.IsTrue(data.InitCheck);
                Assert.AreEqual(data.OldVersion, 0);
                data.TestString = "Test";
            }
            data.SetDitry();

            ctx.Save.TryGet(out data);
            Assert.IsFalse(string.IsNullOrEmpty(data.TestString));
            Assert.IsFalse(data.InitCheck);
            Assert.AreEqual(data.OldVersion, 0);
            data.SetDitry(true);

            TestData.TestVersion = 2;
            ctx.Save.TryGet(out data);
            Assert.AreEqual(data.TestString, "Test");
            Assert.IsFalse(data.InitCheck);
            Assert.AreEqual(data.OldVersion, 1);

            data.TestString = "TestTest";

            data.SetDitry(true);
            ctx.Save.TryGet(out data);
            Assert.AreEqual(data.TestString, "TestTest");
            Assert.IsFalse(data.InitCheck);
            Assert.AreEqual(data.OldVersion, 0);
        }
    }
Exemplo n.º 24
0
    public void MessageTest2()
    {
        EventCall call  = new EventCall();
        int       ret   = 0;
        int       count = 0;
        var       path  = call.Subscribe(TestEvent.Event1, (int val) => { ret = val; count++; });

        //イベントを発行
        Assert.IsTrue(call.Message(TestEvent.Event1, 5));
        Assert.AreEqual(ret, 5);
        Assert.AreEqual(count, 1);

        //イベントを発行
        Assert.IsTrue(call.Message(TestEvent.Event1, 7));
        Assert.AreEqual(ret, 7);
        Assert.AreEqual(count, 2);

        //単発イベントでは発火しない
        Assert.IsFalse(call.Message(TestEvent.Event1));
        Assert.AreEqual(ret, 7);
        Assert.AreEqual(count, 2);

        //違う方のイベントでは発火しない
        Assert.IsFalse(call.Message(TestEvent.Event1, 0.4f));
        Assert.AreEqual(ret, 7);
        Assert.AreEqual(count, 2);

        //登録していないイベント
        Assert.IsFalse(call.Message(TestEvent.Event2, 4));
        Assert.AreEqual(count, 2);

        //パスを解除
        path.Dispose();
        Assert.IsFalse(call.Message(TestEvent.Event1, 22));
        Assert.AreEqual(ret, 7);
        Assert.AreEqual(count, 2);
    }
Exemplo n.º 25
0
    public void TriggerTest5()
    {
        //複数の結果をまとめる
        int[] input    = new int[] { 1, 5, 7, 3, 5, 7 };
        var   triggers = new List <Trigger <int> >();

        for (int i = 0; i < input.Length; i++)
        {
            triggers.Add(new Trigger <int>());
        }
        var combine = Trigger.Combine(triggers.Select(x => x.Action).ToArray());

        //まだ発火していない。
        Assert.IsFalse(combine.Fired);
        combine.Add(x =>
        {
            for (int i = 0; i < input.Length; i++)
            {
                Assert.AreEqual(x[i], input[i], "入力と同じ");
            }
        });
        for (int i = 0; i < input.Length; i++)
        {
            triggers[i].Fire(input[i]);
            if (i == input.Length - 1)
            {
                Assert.IsTrue(combine.Fired);
            }
            else
            {
                Assert.IsFalse(combine.Fired);
            }
        }
        //引数がなければすぐに発火される
        Assert.IsTrue(Trigger.Combine().Fired);
        Assert.IsTrue(Trigger.Combine <bool>().Fired);
    }
Exemplo n.º 26
0
    public IEnumerator EntityBasicMaterialUpdate()
    {
        string entityId   = "1";
        string materialID = "a-material";

        Assert.IsFalse(scene.disposableComponents.ContainsKey(materialID));

        // Instantiate entity with default material
        TestHelpers.InstantiateEntityWithMaterial(scene, entityId, new Vector3(8, 1, 8),
                                                  new BasicMaterial.Model(), materialID);

        var meshObject = scene.entities[entityId].meshRootGameObject;

        Assert.IsTrue(meshObject != null,
                      "Every entity with a shape should have the mandatory 'Mesh' object as a child");

        var meshRenderer      = meshObject.GetComponent <MeshRenderer>();
        var materialComponent = scene.disposableComponents[materialID] as BasicMaterial;

        yield return(materialComponent.routine);

        // Check if material initialized correctly
        {
            Assert.IsTrue(meshRenderer != null, "MeshRenderer must exist");

            var assignedMaterial = meshRenderer.sharedMaterial;
            Assert.IsTrue(meshRenderer != null, "MeshRenderer.sharedMaterial must be the same as assignedMaterial");

            Assert.AreEqual(assignedMaterial, materialComponent.material, "Assigned material");
        }

        // Check default properties
        {
            Assert.IsTrue(materialComponent.material.GetTexture("_BaseMap") == null);
            Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_AlphaClip"));
        }

        DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.MIRROR,
            FilterMode.Bilinear);

        // Update material
        scene.SharedComponentUpdate(materialID, JsonUtility.ToJson(new BasicMaterial.Model
        {
            texture   = dclTexture.id,
            alphaTest = 0.5f,
        }));

        yield return(materialComponent.routine);

        // Check updated properties
        {
            Texture mainTex = materialComponent.material.GetTexture("_BaseMap");
            Assert.IsTrue(mainTex != null);
            Assert.AreApproximatelyEqual(0.5f, materialComponent.material.GetFloat("_Cutoff"));
            Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_AlphaClip"));
            Assert.AreEqual(TextureWrapMode.Mirror, mainTex.wrapMode);
            Assert.AreEqual(FilterMode.Bilinear, mainTex.filterMode);
        }
    }