github.com/iDigitalFlame/xmt@v0.5.4/c2/state_test.go (about)

     1  // Copyright (C) 2020 - 2023 iDigitalFlame
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU General Public License as published by
     5  // the Free Software Foundation, either version 3 of the License, or
     6  // any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU General Public License
    14  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    15  //
    16  
    17  package c2
    18  
    19  import "testing"
    20  
    21  func TestState(t *testing.T) {
    22  	var s state
    23  	if s.Seen() {
    24  		t.Fatalf("TestState(): Seen should return false!")
    25  	}
    26  	if s.Set(stateSeen); !s.Seen() {
    27  		t.Fatalf("TestState(): Seen should return true!")
    28  	}
    29  	if s.SetLast(0xBEEF); s.Last() != 0xBEEF {
    30  		t.Fatalf(`TestState(): Last should return "0xBEEF" not "0x%X"!`, s.Last())
    31  	}
    32  	if s.Moving() {
    33  		t.Fatalf("TestState(): Moving should return false!")
    34  	}
    35  	if s.Set(stateMoving); !s.Moving() {
    36  		t.Fatalf("TestState(): Moving should return true!")
    37  	}
    38  	if s.CanRecv() {
    39  		t.Fatalf("TestState(): Moving CanRecv return false!")
    40  	}
    41  	if s.Set(stateCanRecv); !s.CanRecv() {
    42  		t.Fatalf("TestState(): CanRecv should return true!")
    43  	}
    44  	if s.Set(stateClosed); s.CanRecv() {
    45  		t.Fatalf("TestState(): CanRecv should return false!")
    46  	}
    47  	if !s.Closing() || !s.Shutdown() || !s.SendClosed() || !s.WakeClosed() {
    48  		t.Fatalf("TestState(): Closing should return true!")
    49  	}
    50  	if s.ChannelProxy() {
    51  		t.Fatalf("TestState(): ChannelProxy should return false!")
    52  	}
    53  	if s.Set(stateChannelProxy); !s.ChannelProxy() {
    54  		t.Fatalf("TestState(): ChannelProxy should return true!")
    55  	}
    56  	if s.ChannelUpdated() {
    57  		t.Fatalf("TestState(): ChannelUpdated should return false!")
    58  	}
    59  	if s.Set(stateChannelUpdated); !s.ChannelUpdated() {
    60  		t.Fatalf("TestState(): ChannelUpdated should return true!")
    61  	}
    62  	if !s.SetChannel(true) {
    63  		t.Fatalf("TestState(): SetChannel(true) should return false!")
    64  	}
    65  	if !s.SetChannel(false) {
    66  		t.Fatalf("TestState(): SetChannel(true) should return false!")
    67  	}
    68  	if s.Unset(stateChannelValue); s.SetChannel(false) {
    69  		t.Fatalf("TestState(): SetChannel(true) should return true!")
    70  	}
    71  }