Advertisement
Guest User

Untitled

a guest
Dec 29th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. //#include "../fs.h"
  2. #include <assert.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <signal.h>
  6. #include <stdlib.h>
  7.  
  8. #include <string>
  9. #include <iostream>
  10.  
  11. extern "C" {
  12. #include "uv.h"
  13. }
  14.  
  15. using namespace std;
  16.  
  17. int main() {
  18.  
  19. uv_loop_t* UV_LOOP;
  20. UV_LOOP = uv_default_loop();
  21.  
  22. int n = 2000;
  23. int flags = O_CREAT | O_RDWR;
  24. int mode = S_IRUSR | S_IWUSR;
  25. bool fail = false;
  26.  
  27. string sillystring = "#include <functional>\n"
  28. "#include <iostream>\n"
  29. " class {\n"
  30. " class {\n"
  31. "#define place string(\"world\")\n"
  32. "\n"
  33. "#define bar()\\\n"
  34. " cout << 10 << endl;\n"
  35. "\n"
  36. " public:\n"
  37. " string message = \"hello \" + place;\n"
  38. "\n"
  39. "#undef place\n"
  40. "#undef bar\n"
  41. " } b;\n"
  42. "\n"
  43. "\n"
  44. " public:\n"
  45. " void print() {\n"
  46. " cout << b.message << endl;\n"
  47. " }\n"
  48. "\n"
  49. " } bla;\n"
  50. "\n"
  51. "\n"
  52. " int main() {\n"
  53. "\n"
  54. " bla.print();\n"
  55. " }\n";
  56.  
  57. const char* path = "./out.txt";
  58.  
  59. while(n--) {
  60.  
  61. uv_fs_t stat_req;
  62. uv_fs_t open_req;
  63. uv_fs_t read_req;
  64. uv_fs_t close_req;
  65.  
  66. int statR = uv_fs_stat(UV_LOOP, &stat_req, path, NULL);
  67. const uv_stat_t* stat = static_cast<const uv_stat_t*>(stat_req.ptr);
  68. int fd = uv_fs_open(UV_LOOP, &open_req, path, flags, mode, NULL);
  69.  
  70. int size = (int) stat->st_size;
  71. int offset = 0;
  72.  
  73. uv_buf_t buf;
  74. buf.base = (char *) malloc(size);
  75. buf.len = size;
  76.  
  77. int readR = uv_fs_read(UV_LOOP, &read_req, fd, &buf, 1, offset, NULL);
  78. int closeR = uv_fs_close(UV_LOOP, &close_req, fd, NULL);
  79.  
  80. if (stat_req.result < 0) {
  81. cout << uv_err_name(stat_req.result) << endl;
  82. fail = true;
  83. break;
  84. }
  85.  
  86. if (open_req.result < 0) {
  87. cout << uv_err_name(open_req.result) << endl;
  88. fail = true;
  89. break;
  90. }
  91.  
  92. if (read_req.result < 0) {
  93. cout << uv_err_name(read_req.result) << endl;
  94. fail = true;
  95. break;
  96. }
  97.  
  98. if (close_req.result < 0) {
  99. cout << uv_err_name(close_req.result) << endl;
  100. fail = true;
  101. break;
  102. }
  103.  
  104. uv_fs_req_cleanup(&stat_req);
  105. uv_fs_req_cleanup(&open_req);
  106. uv_fs_req_cleanup(&read_req);
  107. uv_fs_req_cleanup(&close_req);
  108.  
  109. if (sillystring != buf.base) {
  110. fail = true;
  111. break;
  112. }
  113. }
  114.  
  115. cout << (fail ? "fail" : "success") << endl;
  116.  
  117. uv_run(UV_LOOP, UV_RUN_DEFAULT);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement