home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / TestcaseDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.2 KB  |  228 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. // TestcaseDlg.cpp : implementation file
  19. //
  20.  
  21. #include "stdafx.h"
  22. #include "genframe.h"
  23. #include "TestcaseDlg.h"
  24.  
  25.  
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CWhiteBoxDlg dialog
  35.  
  36. CWhiteBoxDlg::CWhiteBoxDlg(CWnd* pParent /*=NULL*/)
  37.     : CDialog(CWhiteBoxDlg::IDD, pParent)
  38. {
  39.     //{{AFX_DATA_INIT(CWhiteBoxDlg)
  40.     //}}AFX_DATA_INIT
  41.     
  42. }
  43.  
  44. CWhiteBoxDlg::~CWhiteBoxDlg()
  45. {
  46. }
  47.  
  48. void CWhiteBoxDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     CDialog::DoDataExchange(pDX);
  51.     //{{AFX_DATA_MAP(CWhiteBoxDlg)
  52.     DDX_Control(pDX, IDC_LIST, m_list);
  53.     DDX_Control(pDX, IDC_DELETE, m_delete);
  54.     //}}AFX_DATA_MAP
  55. }
  56.  
  57. BEGIN_MESSAGE_MAP(CWhiteBoxDlg, CDialog)
  58.     //{{AFX_MSG_MAP(CWhiteBoxDlg)
  59.     ON_BN_CLICKED(IDC_ADD, OnAdd)
  60.     ON_BN_CLICKED(IDC_DELETE, OnDelete)
  61.     ON_BN_CLICKED(IDC_RUN, OnRun)
  62.     ON_BN_CLICKED(IDC_SAVE, OnSave)
  63.     ON_BN_CLICKED(IDC_IMPORT, OnImport)
  64.     ON_LBN_SELCHANGE(IDC_LIST, OnSelChangeList)
  65.     //}}AFX_MSG_MAP
  66. END_MESSAGE_MAP()
  67.  
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CWhiteBoxDlg message handlers
  70.  
  71. BOOL CWhiteBoxDlg::OnInitDialog()
  72. {
  73.     CString text;
  74.  
  75.     CDialog::OnInitDialog();
  76.     ListTestCases();
  77.     
  78.     return TRUE;  // return TRUE  unless you set the focus to a control
  79. }
  80.  
  81.  
  82.  
  83. void CWhiteBoxDlg::OnAdd() 
  84. {
  85.     CTCData* pTestCase = new CTCData;
  86.     CString str;
  87.  
  88.     
  89.     GetDlgItem(IDC_NAME)->GetWindowText(pTestCase->m_strName);
  90.     GetDlgItem(IDC_DESC)->GetWindowText(pTestCase->m_strDesc);
  91.     GetDlgItem(IDC_ID)->GetWindowText(str);
  92.  
  93.     //convert!
  94.     pTestCase->m_nID = atoi((LPCSTR)str);
  95.  
  96.     m_tcManager.AddTestCase(pTestCase);
  97.     
  98.     ListTestCases();
  99.  
  100.     // Reset the text boxes
  101.     GetDlgItem(IDC_NAME)->SetWindowText("");
  102.     GetDlgItem(IDC_DESC)->SetWindowText("");
  103.     GetDlgItem(IDC_ID)->SetWindowText("0");
  104.     
  105.     //GetDlgItem(IDC_NAME)->SetFocus();
  106.     UpdateData(FALSE);
  107. }
  108.  
  109. void CWhiteBoxDlg::OnDelete() 
  110. {
  111.     
  112.     LPINT m_TestCasesToRemove;
  113.     int nWhich, nNumSelected;
  114.         
  115.     nNumSelected = m_list.GetSelCount();
  116.     if (nNumSelected != 0)
  117.     {
  118.         m_TestCasesToRemove = (LPINT)calloc(sizeof(int),nNumSelected);     
  119.         m_list.GetSelItems(nNumSelected,m_TestCasesToRemove);
  120.  
  121.         // append -1 to the end
  122.         //m_TestCasesToRemove[nNumSelected] = -1;
  123.         m_tcManager.RemoveTestCases(m_TestCasesToRemove, nNumSelected);
  124.         
  125.         free(m_TestCasesToRemove);
  126.     }
  127.     ListTestCases();
  128.  
  129. /*    if ( (nWhich = m_list.GetCurSel()) != LB_ERR )
  130.     {
  131.         nTestCase = m_list.GetItemData(nWhich);
  132.         pTCData = (CTCData*)m_tcManager.m_TCData[nTestCase];
  133.         delete pTCData;
  134.         m_tcManager.RemoveTestCase(nTestCase);
  135.         
  136.     }
  137. */
  138.     // Set cursor
  139.     if (nWhich+1 <= m_list.GetCount())
  140.         m_list.SetAnchorIndex(nWhich+1);
  141.     else
  142.     if (nWhich != 0)
  143.         m_list.SetAnchorIndex(nWhich);
  144.     else
  145.         m_delete.EnableWindow(FALSE);
  146.  
  147.  
  148.  
  149. }
  150.  
  151. void CWhiteBoxDlg::OnRun() 
  152. {
  153.  
  154.     LPINT m_TestCasesToRun;
  155.         
  156.     int nNumSelected = m_list.GetSelCount();
  157.     if (nNumSelected != 0)
  158.     {
  159.         m_TestCasesToRun = (LPINT)calloc(sizeof(int),nNumSelected + 1);     
  160.         m_tcManager.m_iNumTestCasesToRun = m_list.GetSelItems(nNumSelected,m_TestCasesToRun);
  161.  
  162.         // append -1 to the end
  163.         m_TestCasesToRun[m_tcManager.m_iNumTestCasesToRun] = -1;
  164.         CDialog::OnOK();
  165.         m_tcManager.ExecuteTestCases(m_TestCasesToRun);
  166.         
  167.         free(m_TestCasesToRun);
  168.     }
  169. }
  170.  
  171. void CWhiteBoxDlg::OnImport()
  172. {
  173.     m_tcManager.LoadData();
  174.     ListTestCases();
  175. }
  176.  
  177. void CWhiteBoxDlg::OnSelChangeList() 
  178. {
  179.     // enable the delete button now that an item has been selected
  180.     m_delete.EnableWindow(TRUE);    
  181. }
  182.  
  183. // Saves Data And Exits
  184. void CWhiteBoxDlg::OnSave() 
  185. {
  186.     // TODO: Add extra validation here
  187.  
  188.     m_tcManager.SaveData();
  189. }
  190.  
  191. void CWhiteBoxDlg::ListTestCases()
  192. {
  193.  
  194.     CTCData* pTCData;
  195.     CString tmpstr, strTestCase;
  196.     int nI;
  197.  
  198.     CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST);
  199.  
  200.     pListBox->ResetContent();
  201.  
  202.     for (nI = 0;nI < m_tcManager.m_TCData.GetSize();nI++)
  203.     {
  204.         pTCData = (CTCData*)m_tcManager.m_TCData[nI];
  205.         tmpstr.Format("%d",pTCData->m_nID);
  206.         strTestCase = pTCData->m_strName + "\t" + pTCData->m_strDesc + "\t" + tmpstr;
  207.  
  208.         m_list.AddString(strTestCase);
  209.         //nWhich = pListBox->AddString(strTestCase);
  210.             //pListBox->SetItemData(nWhich,nI);
  211.  
  212.             /*
  213.             bSelect = FALSE;
  214.             for (nJ = 0;nJ < m_pCourse->m_Students.GetSize();nJ++)
  215.             {
  216.                 if ( m_pCourse->m_Students[nJ] == (DWORD)nI )
  217.                 {
  218.                     bSelect = TRUE;
  219.                     break;
  220.                 }
  221.             }
  222.             if ( bSelect )
  223.                 pListBox->SetSel(nWhich,TRUE);
  224.             */
  225.     }
  226.     
  227. }
  228.