Esempio n. 1
0
def test_ProcessIncomingEntryAssignWithFlags(
    storage_populate_one, dispatcher, entry_notifier, is_server, conn
):
    storage = storage_populate_one
    value = Value.makeDouble(1.0)

    storage.processIncoming(Message.entryAssign("foo", 0, 1, value, 0x2), conn)

    # EXPECT_CALL(*conn, proto_rev()).WillRepeatedly(Return(0x0300u))
    if is_server:
        # server broadcasts new value/flags to all *other* connections
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.entryAssign("foo", 0, 1, value, 0x2), None, conn)]
        )

        entry_notifier.notifyEntry.assert_has_calls(
            [call(0, "foo", value, NT_NOTIFY_UPDATE | NT_NOTIFY_FLAGS)]
        )

    else:
        # client forces flags back when an assign message is received for an
        # existing entry with different flags
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.flagsUpdate(0, 0), None, None)]
        )

        entry_notifier.notifyEntry.assert_has_calls(
            [call(0, "foo", value, NT_NOTIFY_UPDATE)]
        )
Esempio n. 2
0
def test_ProcessIncomingEntryAssignWithFlags(storage_populate_one, dispatcher,
                                             entry_notifier, is_server, conn):
    storage = storage_populate_one
    value = Value.makeDouble(1.0)

    storage.processIncoming(Message.entryAssign("foo", 0, 1, value, 0x2), conn)

    #EXPECT_CALL(*conn, proto_rev()).WillRepeatedly(Return(0x0300u))
    if is_server:
        # server broadcasts new value/flags to all *other* connections
        dispatcher._queueOutgoing.assert_has_calls([
            call(Message.entryAssign("foo", 0, 1, value, 0x2), None, conn),
        ])

        entry_notifier.notifyEntry.assert_has_calls([
            call(0, "foo", value, NT_NOTIFY_UPDATE | NT_NOTIFY_FLAGS),
        ])

    else:
        # client forces flags back when an assign message is received for an
        # existing entry with different flags
        dispatcher._queueOutgoing.assert_has_calls([
            call(Message.flagsUpdate(0, 0), None, None),
        ])

        entry_notifier.notifyEntry.assert_has_calls([
            call(0, "foo", value, NT_NOTIFY_UPDATE),
        ])
Esempio n. 3
0
def test_SetEntryTypeValueAssignNew(
    storage_empty, dispatcher, entry_notifier, is_server
):
    storage = storage_empty

    # brand new entry
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign("foo", 0 if is_server else 0xFFFF, 1, value, 0),
                None,
                None,
            )
        ]
    )
    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)]
    )

    if is_server:
        assert 1 == len(storage.m_idmap)
        assert value == storage.m_idmap[0].value
    else:
        assert len(storage.m_idmap) == 0
Esempio n. 4
0
def test_LoadPersistentAssign(storage_empty, dispatcher, entry_notifier, is_server):
    storage = storage_empty

    fp = StringIO('[NetworkTables Storage 3.0]\nboolean "foo"=true\n')
    assert storage.loadPersistent(fp=fp) is None

    entry = storage.m_entries.get("foo")
    assert Value.makeBoolean(True) == entry.value
    assert NT_PERSISTENT == entry.flags
    assert entry.isPersistent

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign(
                    "foo", 0 if is_server else 0xFFFF, 1, entry.value, NT_PERSISTENT
                ),
                None,
                None,
            )
        ]
    )

    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", entry.value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)]
    )
Esempio n. 5
0
def test_LoadPersistentAssign(storage_empty, dispatcher, entry_notifier, is_server):
    storage = storage_empty

    fp = StringIO('[NetworkTables Storage 3.0]\nboolean "foo"=true\n')
    assert storage.loadPersistent(fp=fp) is None

    entry = storage.m_entries.get("foo")
    assert Value.makeBoolean(True) == entry.value
    assert NT_PERSISTENT == entry.flags

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign(
                    "foo", 0 if is_server else 0xFFFF, 1, entry.value, NT_PERSISTENT
                ),
                None,
                None,
            )
        ]
    )

    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", entry.value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)]
    )
Esempio n. 6
0
def test_SetEntryTypeValueAssignNew(
    storage_empty, dispatcher, entry_notifier, is_server
):
    storage = storage_empty

    # brand new entry
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign("foo", 0 if is_server else 0xFFFF, 1, value, 0),
                None,
                None,
            )
        ]
    )
    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)]
    )

    if is_server:
        assert 1 == len(storage.m_idmap)
        assert value == storage.m_idmap[0].value
    else:
        assert len(storage.m_idmap) == 0
Esempio n. 7
0
def test_ProcessIncomingEntryAssign1(storage_populate_one, dispatcher,
                                     entry_notifier, is_server, conn):
    storage = storage_populate_one
    value = Value.makeDouble(1.0)

    storage.processIncoming(Message.entryAssign("foo", 0, 1, value, 0), conn)

    # EXPECT_CALL(*conn, proto_rev()).WillRepeatedly(Return(0x0300u))
    if is_server:
        # server broadcasts new value to all *other* connections
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.entryAssign("foo", 0, 1, value, 0), None, conn)])
    else:
        assert dispatcher._queueOutgoing.call_count == 0

    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", value, NT_NOTIFY_UPDATE)])
Esempio n. 8
0
def test_ProcessIncomingEntryAssign0(
    storage_empty, dispatcher, entry_notifier, is_server, conn
):
    storage = storage_empty
    value = Value.makeDouble(1.0)

    entry_id = 0xFFFF if is_server else 0

    storage.processIncoming(Message.entryAssign("foo", entry_id, 0, value, 0), conn)

    if is_server:
        # id assign message reply generated on the server sent to everyone
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.entryAssign("foo", 0, 0, value, 0), None, None)]
        )
    else:
        assert dispatcher._queueOutgoing.call_count == 0

    entry_notifier.notifyEntry.assert_has_calls([call(0, "foo", value, NT_NOTIFY_NEW)])
Esempio n. 9
0
def test_ProcessIncomingEntryAssignIgnore(storage_populate_one, dispatcher,
                                          entry_notifier, is_server, conn):
    storage = storage_populate_one
    value = Value.makeDouble(1.0)

    storage.processIncoming(Message.entryAssign("foo", 0xffff, 1, value, 0),
                            conn)

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Esempio n. 10
0
def test_ProcessIncomingEntryAssign0(
    storage_empty, dispatcher, entry_notifier, is_server, conn
):
    storage = storage_empty
    value = Value.makeDouble(1.0)

    entry_id = 0xFFFF if is_server else 0

    storage.processIncoming(Message.entryAssign("foo", entry_id, 0, value, 0), conn)

    if is_server:
        # id assign message reply generated on the server sent to everyone
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.entryAssign("foo", 0, 0, value, 0), None, None)]
        )
    else:
        assert dispatcher._queueOutgoing.call_count == 0

    entry_notifier.notifyEntry.assert_has_calls([call(0, "foo", value, NT_NOTIFY_NEW)])
Esempio n. 11
0
def test_ProcessIncomingEntryAssignIgnore(
    storage_populate_one, dispatcher, entry_notifier, is_server, conn
):
    storage = storage_populate_one
    value = Value.makeDouble(1.0)

    storage.processIncoming(Message.entryAssign("foo", 0xFFFF, 1, value, 0), conn)

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Esempio n. 12
0
def test_ProcessIncomingEntryAssign1(
    storage_populate_one, dispatcher, entry_notifier, is_server, conn
):
    storage = storage_populate_one
    value = Value.makeDouble(1.0)

    storage.processIncoming(Message.entryAssign("foo", 0, 1, value, 0), conn)

    # EXPECT_CALL(*conn, proto_rev()).WillRepeatedly(Return(0x0300u))
    if is_server:
        # server broadcasts new value to all *other* connections
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.entryAssign("foo", 0, 1, value, 0), None, conn)]
        )
    else:
        assert dispatcher._queueOutgoing.call_count == 0

    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", value, NT_NOTIFY_UPDATE)]
    )
Esempio n. 13
0
def test_SetEntryTypeValueAssignTypeChange(storage_populate_one, dispatcher,
                                           entry_notifier, is_server):
    storage = storage_populate_one

    # update with different type results in assignment message
    value = Value.makeDouble(0.0)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls([
        call(
            Message.entryAssign("foo", 0 if is_server else 0xffff, 2, value,
                                0), None, None),
    ])
    entry_notifier.notifyEntry.assert_has_calls([
        call(0, "foo", value, NT_NOTIFY_UPDATE | NT_NOTIFY_LOCAL),
    ])
Esempio n. 14
0
def test_SetEntryValueAssignNew(storage_empty, dispatcher, entry_notifier,
                                is_server):
    storage = storage_empty

    # brand entry
    value = Value.makeBoolean(True)
    assert storage.setEntryValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls([
        call(
            Message.entryAssign("foo", 0 if is_server else 0xffff, 1, value,
                                0), None, None),
    ])
    entry_notifier.notifyEntry.assert_has_calls([
        call(0, "foo", value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL),
    ])
Esempio n. 15
0
def test_SetDefaultEntryAssignNew(storage_empty, dispatcher, entry_notifier, is_server):
    storage = storage_empty

    # brand new entry
    value = Value.makeBoolean(True)
    ret_val = storage.setDefaultEntryValue("foo", value)
    assert ret_val
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign("foo", 0 if is_server else 0xFFFF, 1, value, 0),
                None,
                None,
            )
        ]
    )
    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)]
    )
Esempio n. 16
0
def test_SetEntryTypeValueAssignTypeChange(
    storage_populate_one, dispatcher, entry_notifier, is_server
):
    storage = storage_populate_one

    # update with different type results in assignment message
    value = Value.makeDouble(0.0)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign("foo", 0 if is_server else 0xFFFF, 2, value, 0),
                None,
                None,
            )
        ]
    )
    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", value, NT_NOTIFY_UPDATE | NT_NOTIFY_LOCAL)]
    )
Esempio n. 17
0
def test_wire_entryAssign2(msg_round_trip, proto_rev):
    exclude = [] if proto_rev >= 0x0300 else [4]
    value = Value.makeString("Oh noes")
    msg_round_trip(
        Message.entryAssign("Hi", 0x1234, 0x4321, value, 0x00), exclude=exclude
    )
Esempio n. 18
0
def test_wire_entryAssign1(msg_round_trip, proto_rev):
    exclude = [] if proto_rev >= 0x0300 else [4]
    value = Value.makeBoolean(True)
    msg_round_trip(
        Message.entryAssign("Hi", 0x1234, 0x4321, value, 0x00), exclude=exclude
    )
Esempio n. 19
0
def test_wire_entryAssign2(msg_round_trip, proto_rev):
    exclude = [] if proto_rev >= 0x0300 else [4]
    value = Value.makeString("Oh noes")
    msg_round_trip(Message.entryAssign("Hi", 0x1234, 0x4321, value, 0x00),
                   exclude=exclude)
Esempio n. 20
0
def test_wire_entryAssign1(msg_round_trip, proto_rev):
    exclude = [] if proto_rev >= 0x0300 else [4]
    value = Value.makeBoolean(True)
    msg_round_trip(Message.entryAssign("Hi", 0x1234, 0x4321, value, 0x00),
                   exclude=exclude)