private void TestSubscriptions() { Console.Write(" Subscriptions\n"); Debug.Assert(iDeviceList.Count == 1); CpProxyZappOrgTestBasic1 proxy = new CpProxyZappOrgTestBasic1(iDeviceList[0]); proxy.SetPropertyChanged(UpdatesComplete); proxy.Subscribe(); iUpdatesComplete.WaitOne(); // wait for initial event // set callbacks for individual property changes now to avoid all being run by initial event proxy.SetPropertyVarUintChanged(SingleChanged); proxy.SetPropertyVarIntChanged(SingleChanged); proxy.SetPropertyVarBoolChanged(SingleChanged); proxy.SetPropertyVarStrChanged(SingleChanged); proxy.SetPropertyVarBinChanged(SingleChanged); /* For each property, * call its setter action * wait on a property being updated * check that the property matches the value set * check that the getter action matches the property */ Console.Write(" Uint...\n"); proxy.SyncSetUint(1); iSingleChanged.WaitOne(); uint propUint; proxy.PropertyVarUint(out propUint); Debug.Assert(propUint == 1); uint valUint; proxy.SyncGetUint(out valUint); Debug.Assert(propUint == valUint); Console.Write(" Int...\n"); proxy.SyncSetInt(-99); iSingleChanged.WaitOne(); int propInt; proxy.PropertyVarInt(out propInt); Debug.Assert(propInt == -99); int valInt; proxy.SyncGetInt(out valInt); Debug.Assert(propInt == valInt); Console.Write(" Bool...\n"); proxy.SyncSetBool(true); iSingleChanged.WaitOne(); bool propBool; proxy.PropertyVarBool(out propBool); Debug.Assert(propBool); bool valBool; proxy.SyncGetBool(out valBool); Debug.Assert(valBool); Console.Write(" String...\n"); string str = "<&'tag\">"; proxy.SyncSetString(str); iSingleChanged.WaitOne(); string propStr; proxy.PropertyVarStr(out propStr); Debug.Assert(propStr == str); // test again to check that PropertyVarStr didn't TransferTo the property proxy.PropertyVarStr(out propStr); Debug.Assert(propStr == str); string valStr; GC.Collect(); proxy.SyncGetString(out valStr); Debug.Assert(propStr == valStr); Console.Write(" Binary...\n"); char[] bin = new char[128]; for (int i = 0; i < 127; i++) { bin[i] = (char)(i + 1); } bin[127] = '\0'; string bufBin = new string(bin); proxy.SyncSetBinary(bufBin); iSingleChanged.WaitOne(); string propBin; proxy.PropertyVarBin(out propBin); Debug.Assert(propBin == bufBin); // test again to check that PropertyVarBin didn't TransferTo the property proxy.PropertyVarBin(out propBin); Debug.Assert(propBin == bufBin); string valBin; proxy.SyncGetBinary(out valBin); Debug.Assert(propBin == valBin); Console.Write(" Multiple...\n"); int waitCount = iUpdatesComplete.Release(); waitCount++; while (waitCount > 0) { iUpdatesComplete.WaitOne(); waitCount--; } proxy.SyncSetMultiple(15, 658, false); iUpdatesComplete.WaitOne(); proxy.PropertyVarUint(out propUint); Debug.Assert(propUint == 15); proxy.SyncGetUint(out valUint); Debug.Assert(propUint == valUint); proxy.PropertyVarInt(out propInt); Debug.Assert(propInt == 658); proxy.SyncGetInt(out valInt); Debug.Assert(propInt == valInt); proxy.PropertyVarBool(out propBool); Debug.Assert(!propBool); proxy.SyncGetBool(out valBool); Debug.Assert(!valBool); proxy.Dispose(); // automatically unsubscribes }