Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.7 KiB

  1. #include "fundsrm.h"
  2. #define BUFFER_SIZE 1024
  3. LPTSTR BobName = L"Bob";
  4. LPTSTR MarthaName = L"Martha";
  5. LPTSTR JoeName = L"Joe";
  6. LPTSTR CorporateName = L"Corporate";
  7. LPTSTR TransferName = L"Transfer";
  8. LPTSTR PersonalName = L"Personal";
  9. typedef struct {
  10. LPTSTR Name;
  11. DWORD Amount;
  12. DWORD Type;
  13. } TestStruct;
  14. #define NUM_TESTS 12
  15. TestStruct Tests[NUM_TESTS] =
  16. {
  17. { BobName, 5000000, ACCESS_FUND_CORPORATE },
  18. { MarthaName, 5000000, ACCESS_FUND_CORPORATE },
  19. { JoeName, 4000000, ACCESS_FUND_TRANSFER },
  20. { BobName, 600000, ACCESS_FUND_PERSONAL },
  21. { MarthaName, 200000, ACCESS_FUND_CORPORATE },
  22. { JoeName, 300000, ACCESS_FUND_TRANSFER },
  23. { BobName, 10000, ACCESS_FUND_CORPORATE },
  24. { MarthaName, 70000, ACCESS_FUND_TRANSFER },
  25. { JoeName, 40000, ACCESS_FUND_TRANSFER },
  26. { BobName, 2000, ACCESS_FUND_CORPORATE },
  27. { MarthaName, 7000, ACCESS_FUND_PERSONAL },
  28. { JoeName, 1000, ACCESS_FUND_CORPORATE }
  29. };
  30. void __cdecl wmain(int argc, char *argv[]) {
  31. //
  32. // Initialize the resource manager object
  33. //
  34. FundsRM *pFRM = new FundsRM(2000000000);
  35. /*
  36. Now we are ready to request fund approvals
  37. Again, Bob is a VP, therefore he can approve up to 100000000 cents in spending
  38. Martha is a Manager, so she can approve up to 1000000 cents
  39. Joe is an employee, so he is limited to 50000 in approvals
  40. We have a fund which allows company expenditures and transfers, but does not allow
  41. funds for personal use.
  42. Bob will attempt to get approval for a 50000000 cent ($500k) transfer, he should
  43. succeed.
  44. Bob will also attempt a 20000 cent ($200) personal withdrawal. He should fail,
  45. since the fund does not allow personal use.
  46. Martha will attempt a 500000 ($5k) company spending approval. She should succeed.
  47. Finally, Joe will attempt a 50001 cent ($500.01) transfer. He should fail, since
  48. he is limited to $500 approvals.
  49. */
  50. for(int i=0; i<NUM_TESTS; i++) {
  51. wprintf(L"%s ", Tests[i].Name);
  52. if( pFRM->Authorize(Tests[i].Name, Tests[i].Amount, Tests[i].Type) ) {
  53. wprintf(L"approved for a ");
  54. } else {
  55. wprintf(L"NOT approved for a ");
  56. }
  57. switch(Tests[i].Type) {
  58. case ACCESS_FUND_CORPORATE:
  59. wprintf(L"%s ", CorporateName);
  60. break;
  61. case ACCESS_FUND_TRANSFER:
  62. wprintf(L"%s ", TransferName);
  63. break;
  64. case ACCESS_FUND_PERSONAL:
  65. wprintf(L"%s ", PersonalName);
  66. break;
  67. default:
  68. wprintf(L"unknown ");
  69. }
  70. wprintf(L"expenditure of $%u.%2.2u, $%u.%2.2u left\n",
  71. Tests[i].Amount/100,
  72. Tests[i].Amount%100,
  73. pFRM->FundsAvailable()/100,
  74. pFRM->FundsAvailable()%100);
  75. }
  76. }