Beispiel #1
0
 private void setGridRow(MainWindows.MainWindow amw)
 {
     string[] aRow = new string[] { amw.hWnd.ToString(), amw.title };
     dataGridView1.Rows.Add(aRow);
 }
Beispiel #2
0
      private void blah(List <MainWindows.MainWindow> mws)
      {
          _calls++;
          QuasiLogger.log("blah called mws.Count = " + mws.Count);
          try
          {
              switch (_calls)
              {
              //First only visible windows
              case 1:            //0 ms
              {
                  QuasiLogger.log("calls 1 " + myTime());
                  Assert.AreEqual(mws.Count, 4);
                  //expected handles - four visible windows.
                  List <IntPtr> handles = new List <IntPtr> {
                      (IntPtr)1001, (IntPtr)1003, (IntPtr)1005, (IntPtr)1007
                  };
                  //log
                  foreach (MainWindows.MainWindow w in mws)
                  {
                      QuasiLogger.log("delivered handle: " + w.hWnd.ToString() + " isVisible, title: " + w.title);
                  }
                  foreach (MainWindows.MainWindow w in mws)
                  {
                      QuasiLogger.log("w.hwnd = " + w.hWnd + " " + handles.Contains(w.hWnd));
                      Assert.IsTrue(handles.Contains(w.hWnd));
                      handles.Remove(w.hWnd);
                  }
              }
              break;

              //second: one window is added, a second is deleted; 5 windows expected (see case 1)
              case 2:            //3000ms
              {
                  QuasiLogger.log("calls 2 " + myTime());
                  QuasiLogger.log("n windows: " + mws.Count.ToString());
                  Assert.AreEqual(mws.Count, 5);
                  foreach (MainWindows.MainWindow w in mws)
                  {
                      QuasiLogger.log("delivered handle: " + w.hWnd.ToString() + " title: " + w.title + " flag: " + w.flag);
                  }
                  //expected handles:
                  List <IntPtr> handles = new List <IntPtr> {
                      (IntPtr)1001, (IntPtr)1003, (IntPtr)1005, (IntPtr)1007, (IntPtr)4711
                  };

                  //check the vanished window 1003
                  //var matches = myList.Where(p => p.Name == nameToExtract);
                  var matches = mws.Where(p => p.hWnd.Equals(new IntPtr(1003)));
                  QuasiLogger.log("n matches: " + matches.Count());
                  Assert.IsTrue(matches.Count() == 1);
                  MainWindows.MainWindow mw = (MainWindows.MainWindow)matches.First();
                  QuasiLogger.log("mw.flag: " + mw.flag);
                  Assert.IsTrue(mw.flag == MainWindows.MainWindow.flags.VANISHED);

                  //check the new window
                  matches = mws.Where(p => p.hWnd.Equals(new IntPtr(4711)));
                  QuasiLogger.log("matches for 4711: " + matches.Count());
                  Assert.IsTrue(matches.Count() == 1);
                  mw = (MainWindows.MainWindow)matches.First();
                  Assert.IsTrue(mw.flag == MainWindows.MainWindow.flags.NEW);

                  //check the rest
                  QuasiLogger.log("check the rest");
                  List <IntPtr> same = new List <IntPtr> {
                      new IntPtr(1001), new IntPtr(1005), new IntPtr(1007)
                  };

                  foreach (IntPtr aHandle in same)
                  {
                      matches = mws.Where(p => p.hWnd.Equals(aHandle));
                      Assert.IsTrue(matches.Count() == 1);
                      mw = (MainWindows.MainWindow)matches.First();
                      Assert.IsTrue(mw.flag == MainWindows.MainWindow.flags.SAME);
                  }

                  timeLastCall     = DateTime.Now;
                  unixMilliSeconds = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                  QuasiLogger.log("unixSeconds " + unixMilliSeconds);

                  //we miss a cycle then the windows are changed.
              }
              break;

              //we wait a cycle nothing should be done. we are not even called.
              //All windows are gone except of the one and only last standing window out there: number 1005.
              case 3:
              {
                  QuasiLogger.log("calls 3 " + myTime());
                  int vanishedWindows = 0;
                  int sameWindows     = 0;
                  //three vanished and one stayed
                  foreach (MainWindows.MainWindow w in mws)
                  {
                      QuasiLogger.log("delivered handle: " + w.hWnd.ToString() + " title: " + w.title + " flag: " + w.flag);
                      if (w.flag.Equals(MainWindows.MainWindow.flags.SAME))
                      {
                          sameWindows++;
                      }
                      else if (w.flag.Equals(MainWindows.MainWindow.flags.VANISHED))
                      {
                          vanishedWindows++;
                      }
                      else
                      {
                          Assert.Fail(w.flag + " shouldn't be here.");
                      }
                  }
                  Assert.IsTrue(vanishedWindows == 3);
                  Assert.IsTrue(sameWindows == 1);
                  QuasiLogger.log("myTime " + myTime());

                  //Assert.IsTrue(elapsed > cycle * 2 - 100 && elapsed < cycle * 2 + 100);
              }
              break;

              case 4:
              {
                  QuasiLogger.log("calls " + _calls + " " + myTime());
                  int vanishedWindows = 0;
                  int sameWindows     = 0;
                  int newWindows      = 0;
                  //none vanished one same and a new one
                  foreach (MainWindows.MainWindow w in mws)
                  {
                      QuasiLogger.log("delivered handle: " + w.hWnd.ToString() + " title: " + w.title + " flag: " + w.flag);
                      if (w.flag.Equals(MainWindows.MainWindow.flags.SAME))
                      {
                          sameWindows++;
                      }
                      else if (w.flag.Equals(MainWindows.MainWindow.flags.VANISHED))
                      {
                          vanishedWindows++;
                      }
                      else if (w.flag.Equals(MainWindows.MainWindow.flags.NEW))
                      {
                          newWindows++;
                      }
                      else
                      {
                          Assert.Fail(w.flag + " shouldn't be here.");
                      }
                  }
                  Assert.IsTrue(vanishedWindows == 0);
                  Assert.IsTrue(sameWindows == 1);
                  Assert.IsTrue(newWindows == 1);
                  break;
              }

              default:
              {
                  QuasiLogger.log("default");
                  long elapsed = DateTimeOffset.Now.ToUnixTimeMilliseconds() - unixMilliSeconds;
                  QuasiLogger.log("calls 3 time elapsed: " + elapsed);
                  QuasiLogger.log("calls " + _calls);
                  foreach (MainWindows.MainWindow w in mws)
                  {
                      QuasiLogger.log("delivered handle: " + w.hWnd.ToString() + " title: " + w.title + " flag: " + w.flag);
                  }
                  Assert.Fail("This should never be called.");
              }
              break;
              }
          } catch (Exception ex)
          {
              _ex = ex;
              Console.Write(ex + "\n");
              QuasiLogger.log(ex.StackTrace);
              _hasException = true;
              throw ex;
          }
      }
Beispiel #3
0
 private void setTextBoxText(MainWindows.MainWindow amw)
 {
     textBox2.AppendText("handle: " + amw.hWnd + " title: " + amw.title + "\n");
 }