blob: 59878a1d62d7e9466ebc70bbc3f8db3a32d59c2b [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// 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.
package fsm_test
import (
"fmt"
"testing"
"android.googlesource.com/platform/tools/gpu/framework/assert"
"android.googlesource.com/platform/tools/gpu/framework/fsm"
)
func TestStructure(t *testing.T) {
const expect = `
FSM ==> A
A => B
exit -> D
B
doa -> A (1 hook)
doc -> C
exit -> D
C
doa -> A (2 hooks)
exit -> D (1 hook)
D
exit -> D
`
ctx := assert.Context(t)
compiled, err := fsm.Compile(fsm.FSM{
States: []fsm.State{
{Name: "A"},
{Name: "B"},
{Name: "C"},
{Name: "D"},
},
Transitions: []fsm.Transition{
{From: "A", To: "B"},
{From: fsm.NoneOf("A", "D"), Event: "doa", To: "A"},
{From: "B", Event: "doc", To: "C"},
{Event: "exit", To: "D"},
},
Hooks: []fsm.Hook{
{Event: "doa"},
{From: "C"},
},
})
assert.With(ctx).ThatError(err).Succeeded()
assert.With(ctx).That(fmt.Sprintf("\n%v", compiled)).Equals(expect)
}
func TestMustCompileFailure(t *testing.T) {
ctx := assert.Context(t)
defer func() {
assert.With(ctx).ThatString(recover()).Equals("No states specified")
}()
fsm.MustCompile(fsm.FSM{})
ctx.Error().Log("MustCompile failed to panic")
}