public void TestSetGetItem() { NativeTree tree = new NativeTree(testDlg.IdentifyFromDialogId(1041)); TVITEMEX item = new TVITEMEX(); foreach (TVIF element in (TVIF[])Enum.GetValues(typeof(TVIF))) { item.mask |= element; } foreach (TVIS element in (TVIS[])Enum.GetValues(typeof(TVIS))) { item.stateMask |= element; } //アイテムのすべての情報が正常に取得できることを確認。 item.hItem = tree.Nodes[0]; tree.GetItem(item); Assert.AreEqual("0", item.pszText); Assert.AreEqual(0, item.iImage); Assert.AreEqual(4, item.iSelectedImage); Assert.AreEqual(1, item.cChildren); Assert.AreEqual(new IntPtr(100), item.lParam); Assert.AreEqual((TVIS)0, (item.state & TVIS.EXPANDED)); tree.EmulateExpand(item.hItem, true); tree.GetItem(item); Assert.AreEqual(TVIS.EXPANDED, (item.state & TVIS.EXPANDED)); item.hItem = tree.FindNode(0, 0); //iImageは上記では0確認であるため、念のため、値の入ったアイテムでもテスト。 tree.GetItem(item); Assert.AreEqual(1, item.iImage); //全ての情報情報を設定できることを確認。 item.hItem = tree.Nodes[0]; tree.GetItem(item);//もとに戻す用 TVITEMEX newItem = new TVITEMEX(); newItem.hItem = item.hItem; newItem.mask = item.mask; newItem.pszText = "xxx"; newItem.iImage = 1; newItem.iSelectedImage = 2; newItem.cChildren = 0; newItem.lParam = new IntPtr(200); newItem.stateMask = TVIS.SELECTED; newItem.state = TVIS.SELECTED; tree.EmulateChangeItem(newItem); TVITEMEX check = new TVITEMEX(); check.hItem = item.hItem; check.mask = item.mask; check.stateMask = item.stateMask; tree.GetItem(check); Assert.AreEqual("xxx", check.pszText); Assert.AreEqual(1, check.iImage); Assert.AreEqual(2, check.iSelectedImage); Assert.AreEqual(0, check.cChildren); Assert.AreEqual(new IntPtr(200), check.lParam); Assert.AreEqual(TVIS.SELECTED, check.state & TVIS.SELECTED); }
public void TestEmulateChangeItemEvent() { if (!isUni || !OSUtility.Is7or8()) { //設定によってはこのイベントは発生しない。 return; } NativeTree tree = new NativeTree(testDlg.IdentifyFromDialogId(1041)); TVITEMEX itemOri = new TVITEMEX(); itemOri.hItem = tree.Nodes[0]; tree.GetItem(itemOri); TVITEMEX newItem = new TVITEMEX(); newItem.hItem = itemOri.hItem; newItem.mask = itemOri.mask = TVIF.STATE; newItem.stateMask = TVIS.SELECTED; newItem.state = (TVIS)0; //一度明示的に選択をOFFにする tree.EmulateChangeItem(newItem); //変更 newItem.state = TVIS.SELECTED; Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg, delegate { tree.EmulateChangeItem(newItem); }, new CodeInfo(1041, NativeMethods.WM_NOTIFY, TVN_ITEMCHANGING), new CodeInfo(1041, NativeMethods.WM_NOTIFY, TVN_ITEMCHANGED) )); }