trema 0.4.7 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (718) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +33 -54
  3. data/.hound.yml +3 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +17 -1
  6. data/.travis.yml +14 -18
  7. data/CHANGELOG.md +10 -0
  8. data/Gemfile +1 -26
  9. data/README.md +25 -241
  10. data/Rakefile +4 -1056
  11. data/bin/.gitignore +3 -0
  12. data/bin/trema +163 -237
  13. data/features/cleanup_on_failure.feature +118 -0
  14. data/features/logging.feature +73 -0
  15. data/features/open_flow13.feature +21 -0
  16. data/features/step_definitions/.gitignore +35 -0
  17. data/features/step_definitions/.rubocop.yml +5 -0
  18. data/features/step_definitions/.travis.yml +19 -0
  19. data/features/step_definitions/Gemfile +9 -0
  20. data/features/step_definitions/Guardfile +4 -0
  21. data/features/step_definitions/LICENSE +675 -0
  22. data/features/step_definitions/README.md +7 -0
  23. data/features/step_definitions/Rakefile +10 -0
  24. data/features/step_definitions/show_stats_steps.rb +56 -0
  25. data/features/step_definitions/virtual_link_steps.rb +8 -0
  26. data/features/support/env.rb +0 -73
  27. data/features/support/hooks.rb +6 -50
  28. data/features/trema_delete_link.feature +30 -0
  29. data/features/trema_killall.feature +56 -0
  30. data/features/trema_run.feature +47 -0
  31. data/features/trema_start.feature +73 -0
  32. data/features/trema_stop.feature +50 -0
  33. data/lib/trema.rb +4 -0
  34. data/lib/trema/command.rb +184 -0
  35. data/lib/trema/controller.rb +289 -0
  36. data/lib/trema/dirs.rb +14 -0
  37. data/lib/trema/drb.rb +32 -0
  38. data/lib/trema/logger.rb +63 -0
  39. data/lib/trema/monkey_patch/integer.rb +8 -0
  40. data/lib/trema/monkey_patch/integer/base_conversions.rb +12 -0
  41. data/lib/trema/monkey_patch/integer/durations.rb +12 -0
  42. data/lib/trema/switch.rb +83 -0
  43. data/lib/trema/version.rb +5 -0
  44. data/spec/spec_helper.rb +9 -178
  45. data/spec/trema/controller_spec.rb +4 -53
  46. data/tasks/.gitignore +34 -0
  47. data/tasks/LICENSE +675 -0
  48. data/tasks/README.md +6 -0
  49. data/tasks/cucumber.rake +14 -0
  50. data/tasks/flay.rake +15 -0
  51. data/tasks/flog.rake +25 -0
  52. data/tasks/gem.rake +15 -0
  53. data/tasks/reek.rake +11 -0
  54. data/tasks/relish.rake +8 -0
  55. data/tasks/rspec.rake +8 -0
  56. data/tasks/rubocop.rake +2 -16
  57. data/tasks/yard.rake +11 -0
  58. data/trema.gemspec +24 -23
  59. metadata +180 -720
  60. data/.yardopts +0 -4
  61. data/Doxyfile +0 -1679
  62. data/Guardfile +0 -14
  63. data/bin/quality +0 -31
  64. data/bin/trema-config +0 -59
  65. data/build.rb +0 -32
  66. data/cruise.rb +0 -409
  67. data/features/.nav +0 -50
  68. data/features/README.md +0 -7
  69. data/features/core/get_pid_by_trema_name.feature +0 -137
  70. data/features/core/packetin_filter.feature +0 -55
  71. data/features/core/switch_manager.feature +0 -41
  72. data/features/core/trema-config.feature +0 -55
  73. data/features/dsl/switch_port_specifier.feature +0 -15
  74. data/features/examples/dumper.feature +0 -35
  75. data/features/examples/hello_trema.feature +0 -23
  76. data/features/examples/learning_switch.feature +0 -37
  77. data/features/examples/list_switches.feature +0 -24
  78. data/features/examples/message.set_config.feature +0 -27
  79. data/features/examples/message.vendor-action.feature +0 -25
  80. data/features/examples/message.vendor-stats-request.feature +0 -20
  81. data/features/examples/multi_learning_switch.feature +0 -107
  82. data/features/examples/openflow_message.echo.feature +0 -59
  83. data/features/examples/openflow_message.features_request.feature +0 -35
  84. data/features/examples/openflow_message.hello.feature +0 -59
  85. data/features/examples/packet_in.feature +0 -33
  86. data/features/examples/packetin_filter_config.feature +0 -95
  87. data/features/examples/patch_panel.feature +0 -29
  88. data/features/examples/repeater_hub.feature +0 -52
  89. data/features/examples/switch_info.feature +0 -51
  90. data/features/examples/switch_monitor.feature +0 -35
  91. data/features/examples/transparent_firewall.feature +0 -73
  92. data/features/handlers/switch_ready.feature +0 -40
  93. data/features/step_definitions/misc_steps.rb +0 -85
  94. data/features/step_definitions/send_packets_steps.rb +0 -33
  95. data/features/step_definitions/stats_steps.rb +0 -39
  96. data/features/switch_event/C-add_forward_entry.feature +0 -114
  97. data/features/switch_event/C-delete_forward_entry.feature +0 -85
  98. data/features/switch_event/C-dump_forward_entries.feature +0 -72
  99. data/features/switch_event/C-set_forward_entries.feature +0 -77
  100. data/features/switch_event/README.md +0 -40
  101. data/features/switch_event/add_forward_entry.feature +0 -160
  102. data/features/switch_event/delete_forward_entry.feature +0 -160
  103. data/features/switch_event/dump_forward_entries.feature +0 -103
  104. data/features/switch_event/set_forward_entries.feature +0 -102
  105. data/features/trema_commands/README.md +0 -8
  106. data/features/trema_commands/dump_flows.feature +0 -41
  107. data/features/trema_commands/help.feature +0 -27
  108. data/features/trema_commands/help_option.feature +0 -20
  109. data/features/trema_commands/kill.feature +0 -56
  110. data/features/trema_commands/killall.feature +0 -32
  111. data/features/trema_commands/port_down.feature +0 -71
  112. data/features/trema_commands/port_up.feature +0 -75
  113. data/features/trema_commands/reset_stats.feature +0 -56
  114. data/features/trema_commands/run.feature +0 -56
  115. data/features/trema_commands/send_packets.feature +0 -46
  116. data/features/trema_commands/show_stats.feature +0 -66
  117. data/features/trema_commands/up.feature +0 -34
  118. data/features/trema_commands/version.feature +0 -10
  119. data/features/trema_commands/version_option.feature +0 -8
  120. data/rubocop-todo.yml +0 -159
  121. data/ruby/.gitignore +0 -4
  122. data/ruby/blocker.rb +0 -74
  123. data/ruby/extconf.rb +0 -80
  124. data/ruby/sub-process.rb +0 -289
  125. data/ruby/trema/action-common.c +0 -46
  126. data/ruby/trema/action-common.h +0 -38
  127. data/ruby/trema/action.rb +0 -33
  128. data/ruby/trema/aggregate-stats-reply.rb +0 -68
  129. data/ruby/trema/app.rb +0 -114
  130. data/ruby/trema/barrier-reply.c +0 -98
  131. data/ruby/trema/barrier-reply.h +0 -44
  132. data/ruby/trema/barrier-request.c +0 -135
  133. data/ruby/trema/barrier-request.h +0 -42
  134. data/ruby/trema/cli.rb +0 -267
  135. data/ruby/trema/command.rb +0 -41
  136. data/ruby/trema/command/dump_flows.rb +0 -43
  137. data/ruby/trema/command/kill.rb +0 -75
  138. data/ruby/trema/command/killall.rb +0 -38
  139. data/ruby/trema/command/netns.rb +0 -38
  140. data/ruby/trema/command/port_down.rb +0 -43
  141. data/ruby/trema/command/port_up.rb +0 -43
  142. data/ruby/trema/command/reset_stats.rb +0 -41
  143. data/ruby/trema/command/ruby.rb +0 -38
  144. data/ruby/trema/command/run.rb +0 -110
  145. data/ruby/trema/command/send_packets.rb +0 -46
  146. data/ruby/trema/command/shell.rb +0 -57
  147. data/ruby/trema/command/show_stats.rb +0 -65
  148. data/ruby/trema/command/up.rb +0 -44
  149. data/ruby/trema/command/version.rb +0 -35
  150. data/ruby/trema/compat.h +0 -36
  151. data/ruby/trema/controller.c +0 -691
  152. data/ruby/trema/controller.h +0 -42
  153. data/ruby/trema/controller.rb +0 -255
  154. data/ruby/trema/custom-switch.rb +0 -56
  155. data/ruby/trema/daemon.rb +0 -184
  156. data/ruby/trema/default-logger.c +0 -161
  157. data/ruby/trema/default-logger.h +0 -42
  158. data/ruby/trema/default-logger.rb +0 -29
  159. data/ruby/trema/default_openflow_channel_port.rb +0 -26
  160. data/ruby/trema/desc-stats-reply.rb +0 -75
  161. data/ruby/trema/dsl.rb +0 -32
  162. data/ruby/trema/dsl/configuration.rb +0 -145
  163. data/ruby/trema/dsl/context.rb +0 -69
  164. data/ruby/trema/dsl/custom-switch.rb +0 -44
  165. data/ruby/trema/dsl/link.rb +0 -39
  166. data/ruby/trema/dsl/netns.rb +0 -78
  167. data/ruby/trema/dsl/parser.rb +0 -70
  168. data/ruby/trema/dsl/rswitch.rb +0 -47
  169. data/ruby/trema/dsl/run.rb +0 -47
  170. data/ruby/trema/dsl/runner.rb +0 -178
  171. data/ruby/trema/dsl/stanza.rb +0 -51
  172. data/ruby/trema/dsl/switch.rb +0 -76
  173. data/ruby/trema/dsl/syntax-error.rb +0 -31
  174. data/ruby/trema/dsl/syntax.rb +0 -128
  175. data/ruby/trema/dsl/vhost.rb +0 -106
  176. data/ruby/trema/dsl/vswitch.rb +0 -45
  177. data/ruby/trema/echo-reply.c +0 -122
  178. data/ruby/trema/echo-reply.h +0 -40
  179. data/ruby/trema/echo-request.c +0 -117
  180. data/ruby/trema/echo-request.h +0 -40
  181. data/ruby/trema/echo.c +0 -99
  182. data/ruby/trema/echo.h +0 -39
  183. data/ruby/trema/enqueue.rb +0 -87
  184. data/ruby/trema/error.c +0 -262
  185. data/ruby/trema/error.h +0 -42
  186. data/ruby/trema/exact-match.rb +0 -34
  187. data/ruby/trema/executables.rb +0 -99
  188. data/ruby/trema/features-reply.c +0 -330
  189. data/ruby/trema/features-reply.h +0 -54
  190. data/ruby/trema/features-request.c +0 -134
  191. data/ruby/trema/features-request.h +0 -42
  192. data/ruby/trema/flow-mod.c +0 -150
  193. data/ruby/trema/flow-mod.h +0 -42
  194. data/ruby/trema/flow-removed.c +0 -280
  195. data/ruby/trema/flow-removed.h +0 -44
  196. data/ruby/trema/flow-stats-reply.rb +0 -107
  197. data/ruby/trema/flow.rb +0 -65
  198. data/ruby/trema/get-config-reply.c +0 -158
  199. data/ruby/trema/get-config-reply.h +0 -50
  200. data/ruby/trema/get-config-request.c +0 -136
  201. data/ruby/trema/get-config-request.h +0 -42
  202. data/ruby/trema/hardware-switch.rb +0 -86
  203. data/ruby/trema/hello.c +0 -133
  204. data/ruby/trema/hello.h +0 -42
  205. data/ruby/trema/host.rb +0 -263
  206. data/ruby/trema/link.rb +0 -177
  207. data/ruby/trema/list-switches-reply.c +0 -44
  208. data/ruby/trema/list-switches-reply.h +0 -38
  209. data/ruby/trema/mac.rb +0 -29
  210. data/ruby/trema/match.c +0 -621
  211. data/ruby/trema/match.h +0 -34
  212. data/ruby/trema/monkey-patch/integer.rb +0 -35
  213. data/ruby/trema/monkey-patch/integer/base-conversions.rb +0 -34
  214. data/ruby/trema/monkey-patch/integer/ranges.rb +0 -49
  215. data/ruby/trema/monkey-patch/integer/validators.rb +0 -36
  216. data/ruby/trema/monkey-patch/module.rb +0 -33
  217. data/ruby/trema/monkey-patch/module/class-method.rb +0 -38
  218. data/ruby/trema/monkey-patch/module/deprecation.rb +0 -39
  219. data/ruby/trema/monkey-patch/string.rb +0 -31
  220. data/ruby/trema/monkey-patch/string/inflectors.rb +0 -52
  221. data/ruby/trema/netns.rb +0 -127
  222. data/ruby/trema/network-component.rb +0 -151
  223. data/ruby/trema/ofctl.rb +0 -70
  224. data/ruby/trema/open-vswitch.rb +0 -160
  225. data/ruby/trema/openflow-error.c +0 -193
  226. data/ruby/trema/openflow-error.h +0 -51
  227. data/ruby/trema/openflow-switch.rb +0 -35
  228. data/ruby/trema/ordered-hash.rb +0 -75
  229. data/ruby/trema/packet-in.c +0 -1365
  230. data/ruby/trema/packet-in.h +0 -44
  231. data/ruby/trema/packet-queue.rb +0 -181
  232. data/ruby/trema/packetin-filter.rb +0 -124
  233. data/ruby/trema/path.rb +0 -85
  234. data/ruby/trema/phost.rb +0 -76
  235. data/ruby/trema/port-mod.c +0 -232
  236. data/ruby/trema/port-mod.h +0 -34
  237. data/ruby/trema/port-stats-reply.rb +0 -109
  238. data/ruby/trema/port-status-add.rb +0 -60
  239. data/ruby/trema/port-status-delete.rb +0 -60
  240. data/ruby/trema/port-status-modify.rb +0 -60
  241. data/ruby/trema/port-status.c +0 -192
  242. data/ruby/trema/port-status.h +0 -41
  243. data/ruby/trema/port.c +0 -398
  244. data/ruby/trema/port.h +0 -45
  245. data/ruby/trema/process.rb +0 -103
  246. data/ruby/trema/queue-get-config-reply.c +0 -205
  247. data/ruby/trema/queue-get-config-reply.h +0 -45
  248. data/ruby/trema/queue-get-config-request.c +0 -141
  249. data/ruby/trema/queue-get-config-request.h +0 -42
  250. data/ruby/trema/queue-stats-reply.rb +0 -76
  251. data/ruby/trema/ruby-switch.rb +0 -62
  252. data/ruby/trema/send-out-port.rb +0 -113
  253. data/ruby/trema/set-config.c +0 -174
  254. data/ruby/trema/set-config.h +0 -42
  255. data/ruby/trema/set-eth-addr.rb +0 -54
  256. data/ruby/trema/set-eth-dst-addr.rb +0 -52
  257. data/ruby/trema/set-eth-src-addr.rb +0 -53
  258. data/ruby/trema/set-ip-addr.rb +0 -54
  259. data/ruby/trema/set-ip-dst-addr.rb +0 -53
  260. data/ruby/trema/set-ip-src-addr.rb +0 -52
  261. data/ruby/trema/set-ip-tos.rb +0 -64
  262. data/ruby/trema/set-transport-dst-port.rb +0 -53
  263. data/ruby/trema/set-transport-port.rb +0 -53
  264. data/ruby/trema/set-transport-src-port.rb +0 -54
  265. data/ruby/trema/set-vlan-priority.rb +0 -66
  266. data/ruby/trema/set-vlan-vid.rb +0 -65
  267. data/ruby/trema/shell.rb +0 -37
  268. data/ruby/trema/shell/down.rb +0 -37
  269. data/ruby/trema/shell/killall.rb +0 -38
  270. data/ruby/trema/shell/link.rb +0 -59
  271. data/ruby/trema/shell/reset_stats.rb +0 -49
  272. data/ruby/trema/shell/run.rb +0 -67
  273. data/ruby/trema/shell/send_packets.rb +0 -40
  274. data/ruby/trema/shell/show_stats.rb +0 -47
  275. data/ruby/trema/shell/up.rb +0 -41
  276. data/ruby/trema/shell/vhost.rb +0 -42
  277. data/ruby/trema/shell/vswitch.rb +0 -47
  278. data/ruby/trema/stats-helper.rb +0 -63
  279. data/ruby/trema/stats-reply.c +0 -540
  280. data/ruby/trema/stats-reply.h +0 -51
  281. data/ruby/trema/stats-request.c +0 -715
  282. data/ruby/trema/stats-request.h +0 -40
  283. data/ruby/trema/strip-vlan-header.rb +0 -41
  284. data/ruby/trema/switch-daemon.rb +0 -90
  285. data/ruby/trema/switch-disconnected.c +0 -38
  286. data/ruby/trema/switch-disconnected.h +0 -36
  287. data/ruby/trema/switch-event.c +0 -648
  288. data/ruby/trema/switch-event.h +0 -27
  289. data/ruby/trema/switch-manager.rb +0 -119
  290. data/ruby/trema/switch.c +0 -197
  291. data/ruby/trema/switch.h +0 -40
  292. data/ruby/trema/switch.rb +0 -56
  293. data/ruby/trema/table-stats-reply.rb +0 -85
  294. data/ruby/trema/timers.rb +0 -95
  295. data/ruby/trema/trema-ruby-utils.c +0 -66
  296. data/ruby/trema/trema-ruby-utils.h +0 -42
  297. data/ruby/trema/trema.c +0 -126
  298. data/ruby/trema/tremashark.rb +0 -46
  299. data/ruby/trema/util.rb +0 -116
  300. data/ruby/trema/vendor-action.rb +0 -82
  301. data/ruby/trema/vendor-stats-reply.rb +0 -64
  302. data/ruby/trema/vendor.c +0 -230
  303. data/ruby/trema/vendor.h +0 -48
  304. data/ruby/trema/version.rb +0 -28
  305. data/spec/support/action.rb +0 -49
  306. data/spec/support/mandatory-option.rb +0 -53
  307. data/spec/support/matchers/constant.rb +0 -25
  308. data/spec/support/openflow-message.rb +0 -173
  309. data/spec/support/port-status.rb +0 -35
  310. data/spec/trema/app_spec.rb +0 -88
  311. data/spec/trema/barrier-reply_spec.rb +0 -43
  312. data/spec/trema/barrier-request_spec.rb +0 -92
  313. data/spec/trema/cli_spec.rb +0 -156
  314. data/spec/trema/default-logger_spec.rb +0 -46
  315. data/spec/trema/dsl/configuration_spec.rb +0 -120
  316. data/spec/trema/dsl/link_spec.rb +0 -50
  317. data/spec/trema/dsl/run_spec.rb +0 -72
  318. data/spec/trema/dsl/runner_spec.rb +0 -247
  319. data/spec/trema/dsl/switch_spec.rb +0 -69
  320. data/spec/trema/dsl/syntax_spec.rb +0 -110
  321. data/spec/trema/dsl/vhost_spec.rb +0 -144
  322. data/spec/trema/dsl/vswitch_spec.rb +0 -80
  323. data/spec/trema/echo-reply_spec.rb +0 -84
  324. data/spec/trema/echo-request_spec.rb +0 -128
  325. data/spec/trema/enqueue_spec.rb +0 -76
  326. data/spec/trema/error_spec.rb +0 -81
  327. data/spec/trema/executables_spec.rb +0 -54
  328. data/spec/trema/features-reply_spec.rb +0 -91
  329. data/spec/trema/features-request_spec.rb +0 -93
  330. data/spec/trema/flow-mod_spec.rb +0 -99
  331. data/spec/trema/flow-removed_spec.rb +0 -144
  332. data/spec/trema/get-config-reply_spec.rb +0 -43
  333. data/spec/trema/get-config-request_spec.rb +0 -92
  334. data/spec/trema/hardware-switch_spec.rb +0 -54
  335. data/spec/trema/hello_spec.rb +0 -63
  336. data/spec/trema/host_spec.rb +0 -191
  337. data/spec/trema/link_spec.rb +0 -62
  338. data/spec/trema/list-switches-reply_spec.rb +0 -46
  339. data/spec/trema/match_spec.rb +0 -111
  340. data/spec/trema/open-vswitch_spec.rb +0 -121
  341. data/spec/trema/openflow-error_spec.rb +0 -141
  342. data/spec/trema/packet-in_spec.rb +0 -717
  343. data/spec/trema/packet-out_spec.rb +0 -125
  344. data/spec/trema/packetin-filter_spec.rb +0 -39
  345. data/spec/trema/port-mod_spec.rb +0 -98
  346. data/spec/trema/port-status-add_spec.rb +0 -32
  347. data/spec/trema/port-status-delete_spec.rb +0 -32
  348. data/spec/trema/port-status-modify_spec.rb +0 -71
  349. data/spec/trema/port-status_spec.rb +0 -38
  350. data/spec/trema/port_spec.rb +0 -59
  351. data/spec/trema/process_spec.rb +0 -69
  352. data/spec/trema/queue-get-config-reply_spec.rb +0 -65
  353. data/spec/trema/queue-get-config-request_spec.rb +0 -67
  354. data/spec/trema/send-out-port_spec.rb +0 -106
  355. data/spec/trema/set-config_spec.rb +0 -78
  356. data/spec/trema/set-eth-addr_spec.rb +0 -62
  357. data/spec/trema/set-ip-addr_spec.rb +0 -81
  358. data/spec/trema/set-ip-tos_spec.rb +0 -70
  359. data/spec/trema/set-transport-dst-port_spec.rb +0 -65
  360. data/spec/trema/set-transport-src-port_spec.rb +0 -65
  361. data/spec/trema/set-vlan-priority_spec.rb +0 -65
  362. data/spec/trema/set-vlan-vid_spec.rb +0 -65
  363. data/spec/trema/shell/vhost_spec.rb +0 -58
  364. data/spec/trema/shell/vswitch_spec.rb +0 -87
  365. data/spec/trema/stats-reply_spec.rb +0 -363
  366. data/spec/trema/stats-request_spec.rb +0 -166
  367. data/spec/trema/strip-vlan-header_spec.rb +0 -44
  368. data/spec/trema/switch-daemon_spec.rb +0 -81
  369. data/spec/trema/switch-disconnected_spec.rb +0 -56
  370. data/spec/trema/switch-manager_spec.rb +0 -41
  371. data/spec/trema/tremashark_spec.rb +0 -39
  372. data/spec/trema/util_spec.rb +0 -88
  373. data/spec/trema/vendor-action_spec.rb +0 -75
  374. data/spec/trema/vendor_spec.rb +0 -76
  375. data/spec/trema_spec.rb +0 -94
  376. data/src/examples/cbench_switch/README +0 -21
  377. data/src/examples/cbench_switch/cbench-switch.rb +0 -38
  378. data/src/examples/cbench_switch/cbench_switch.c +0 -66
  379. data/src/examples/dumper/dumper.c +0 -362
  380. data/src/examples/dumper/dumper.conf +0 -7
  381. data/src/examples/dumper/dumper.rb +0 -195
  382. data/src/examples/hello_trema/.gitignore +0 -2
  383. data/src/examples/hello_trema/README.md +0 -2
  384. data/src/examples/hello_trema/hello-trema.rb +0 -30
  385. data/src/examples/hello_trema/hello_trema.c +0 -48
  386. data/src/examples/hello_trema/sample.conf +0 -1
  387. data/src/examples/learning_switch/README +0 -15
  388. data/src/examples/learning_switch/fdb.rb +0 -110
  389. data/src/examples/learning_switch/learning-switch.rb +0 -90
  390. data/src/examples/learning_switch/learning_switch.c +0 -217
  391. data/src/examples/learning_switch/learning_switch.conf +0 -18
  392. data/src/examples/list_switches/README +0 -19
  393. data/src/examples/list_switches/list-switches.rb +0 -43
  394. data/src/examples/list_switches/list_switches.c +0 -79
  395. data/src/examples/list_switches/list_switches.conf +0 -15
  396. data/src/examples/match_compare/match-compare.conf +0 -30
  397. data/src/examples/match_compare/match-compare.rb +0 -97
  398. data/src/examples/multi_learning_switch/README +0 -14
  399. data/src/examples/multi_learning_switch/multi-learning-switch.rb +0 -94
  400. data/src/examples/multi_learning_switch/multi_learning_switch.c +0 -294
  401. data/src/examples/multi_learning_switch/multi_learning_switch.conf +0 -17
  402. data/src/examples/openflow_message/README +0 -11
  403. data/src/examples/openflow_message/echo.c +0 -80
  404. data/src/examples/openflow_message/echo.rb +0 -56
  405. data/src/examples/openflow_message/example.rb +0 -60
  406. data/src/examples/openflow_message/features-request.rb +0 -96
  407. data/src/examples/openflow_message/features_request.c +0 -167
  408. data/src/examples/openflow_message/hello.c +0 -68
  409. data/src/examples/openflow_message/hello.rb +0 -43
  410. data/src/examples/openflow_message/set-config.rb +0 -57
  411. data/src/examples/openflow_message/set_config.c +0 -68
  412. data/src/examples/openflow_message/vendor-action.rb +0 -43
  413. data/src/examples/openflow_message/vendor-stats-request.rb +0 -66
  414. data/src/examples/openflow_message/vendor_action.c +0 -103
  415. data/src/examples/openflow_switch/echo_switch.c +0 -89
  416. data/src/examples/openflow_switch/hello_switch.c +0 -85
  417. data/src/examples/packet_in/README +0 -15
  418. data/src/examples/packet_in/packet-in.rb +0 -37
  419. data/src/examples/packet_in/packet_in.c +0 -53
  420. data/src/examples/packet_in/packet_in.conf +0 -15
  421. data/src/examples/packetin_filter_config/README +0 -12
  422. data/src/examples/packetin_filter_config/add_filter.c +0 -71
  423. data/src/examples/packetin_filter_config/delete_filter.c +0 -63
  424. data/src/examples/packetin_filter_config/delete_filter_strict.c +0 -73
  425. data/src/examples/packetin_filter_config/dump_filter.c +0 -63
  426. data/src/examples/packetin_filter_config/dump_filter_strict.c +0 -73
  427. data/src/examples/packetin_filter_config/packetin_filter_config.c +0 -132
  428. data/src/examples/packetin_filter_config/packetin_filter_config.conf +0 -7
  429. data/src/examples/packetin_filter_config/utils.c +0 -100
  430. data/src/examples/packetin_filter_config/utils.h +0 -40
  431. data/src/examples/patch_panel/network.conf +0 -14
  432. data/src/examples/patch_panel/patch-panel.conf +0 -1
  433. data/src/examples/patch_panel/patch-panel.rb +0 -59
  434. data/src/examples/repeater_hub/README +0 -8
  435. data/src/examples/repeater_hub/repeater-hub.rb +0 -41
  436. data/src/examples/repeater_hub/repeater-hub_spec.rb +0 -154
  437. data/src/examples/repeater_hub/repeater_hub.c +0 -81
  438. data/src/examples/repeater_hub/repeater_hub.conf +0 -28
  439. data/src/examples/simple_router/README +0 -18
  440. data/src/examples/simple_router/arp-table.rb +0 -81
  441. data/src/examples/simple_router/interface.rb +0 -90
  442. data/src/examples/simple_router/routing-table.rb +0 -60
  443. data/src/examples/simple_router/simple-router.rb +0 -191
  444. data/src/examples/simple_router/simple_router.conf +0 -24
  445. data/src/examples/simple_router/simple_router_netns.conf +0 -15
  446. data/src/examples/simple_router/simple_router_network.conf +0 -6
  447. data/src/examples/switch_event_config/.gitignore +0 -6
  448. data/src/examples/switch_event_config/add_forward_entry.c +0 -227
  449. data/src/examples/switch_event_config/delete_forward_entry.c +0 -226
  450. data/src/examples/switch_event_config/dump_forward_entries.c +0 -190
  451. data/src/examples/switch_event_config/network.conf +0 -2
  452. data/src/examples/switch_event_config/set_forward_entries.c +0 -210
  453. data/src/examples/switch_info/README +0 -13
  454. data/src/examples/switch_info/switch-info.rb +0 -44
  455. data/src/examples/switch_info/switch_info.c +0 -78
  456. data/src/examples/switch_info/switch_info.conf +0 -3
  457. data/src/examples/switch_monitor/switch-monitor.conf +0 -3
  458. data/src/examples/switch_monitor/switch-monitor.rb +0 -56
  459. data/src/examples/switch_monitor/switch_monitor.c +0 -152
  460. data/src/examples/traffic_monitor/counter.c +0 -72
  461. data/src/examples/traffic_monitor/counter.h +0 -46
  462. data/src/examples/traffic_monitor/counter.rb +0 -44
  463. data/src/examples/traffic_monitor/fdb.c +0 -74
  464. data/src/examples/traffic_monitor/fdb.h +0 -48
  465. data/src/examples/traffic_monitor/fdb.rb +0 -42
  466. data/src/examples/traffic_monitor/traffic-monitor.rb +0 -98
  467. data/src/examples/traffic_monitor/traffic_monitor.c +0 -161
  468. data/src/examples/traffic_monitor/traffic_monitor.conf +0 -16
  469. data/src/examples/transparent_firewall/README.md +0 -61
  470. data/src/examples/transparent_firewall/aggregated-delegated-afrinic.txt +0 -713
  471. data/src/examples/transparent_firewall/aggregated-delegated-apnic.txt +0 -3440
  472. data/src/examples/transparent_firewall/aggregated-delegated-arin.txt +0 -11342
  473. data/src/examples/transparent_firewall/aggregated-delegated-lacnic.txt +0 -1937
  474. data/src/examples/transparent_firewall/aggregated-delegated-ripencc.txt +0 -7329
  475. data/src/examples/transparent_firewall/block-rfc1918.rb +0 -86
  476. data/src/examples/transparent_firewall/pass-delegated.rb +0 -178
  477. data/src/examples/transparent_firewall/regen_aggregated.sh +0 -53
  478. data/src/examples/transparent_firewall/stats-to-cidrs.rb +0 -59
  479. data/src/lib/arp.h +0 -64
  480. data/src/lib/bool.h +0 -47
  481. data/src/lib/buffer.c +0 -304
  482. data/src/lib/buffer.h +0 -54
  483. data/src/lib/byteorder.c +0 -571
  484. data/src/lib/byteorder.h +0 -108
  485. data/src/lib/checks.h +0 -40
  486. data/src/lib/chibach.c +0 -392
  487. data/src/lib/chibach.h +0 -69
  488. data/src/lib/chibach_private.c +0 -168
  489. data/src/lib/chibach_private.h +0 -50
  490. data/src/lib/daemon.c +0 -429
  491. data/src/lib/daemon.h +0 -40
  492. data/src/lib/doubly_linked_list.c +0 -284
  493. data/src/lib/doubly_linked_list.h +0 -86
  494. data/src/lib/ether.c +0 -47
  495. data/src/lib/ether.h +0 -92
  496. data/src/lib/etherip.h +0 -44
  497. data/src/lib/event_forward_interface.c +0 -788
  498. data/src/lib/event_forward_interface.h +0 -138
  499. data/src/lib/event_handler.c +0 -419
  500. data/src/lib/event_handler.h +0 -57
  501. data/src/lib/external_callback.c +0 -126
  502. data/src/lib/external_callback.h +0 -46
  503. data/src/lib/hash_table.c +0 -415
  504. data/src/lib/hash_table.h +0 -136
  505. data/src/lib/icmp.h +0 -72
  506. data/src/lib/igmp.h +0 -48
  507. data/src/lib/ipv4.h +0 -64
  508. data/src/lib/ipv6.h +0 -46
  509. data/src/lib/linked_list.c +0 -244
  510. data/src/lib/linked_list.h +0 -84
  511. data/src/lib/log.c +0 -636
  512. data/src/lib/log.h +0 -77
  513. data/src/lib/management_interface.c +0 -359
  514. data/src/lib/management_interface.h +0 -40
  515. data/src/lib/management_service_interface.c +0 -102
  516. data/src/lib/management_service_interface.h +0 -134
  517. data/src/lib/match.h +0 -82
  518. data/src/lib/match_table.c +0 -606
  519. data/src/lib/match_table.h +0 -49
  520. data/src/lib/message_queue.c +0 -143
  521. data/src/lib/message_queue.h +0 -59
  522. data/src/lib/messenger.c +0 -1821
  523. data/src/lib/messenger.h +0 -145
  524. data/src/lib/openflow_application_interface.c +0 -1800
  525. data/src/lib/openflow_application_interface.h +0 -359
  526. data/src/lib/openflow_message.c +0 -4240
  527. data/src/lib/openflow_message.h +0 -291
  528. data/src/lib/openflow_service_interface.h +0 -58
  529. data/src/lib/openflow_switch_interface.c +0 -1378
  530. data/src/lib/openflow_switch_interface.h +0 -262
  531. data/src/lib/packet_info.c +0 -336
  532. data/src/lib/packet_info.h +0 -233
  533. data/src/lib/packet_parser.c +0 -522
  534. data/src/lib/packetin_filter_interface.c +0 -292
  535. data/src/lib/packetin_filter_interface.h +0 -125
  536. data/src/lib/persistent_storage.c +0 -478
  537. data/src/lib/persistent_storage.h +0 -44
  538. data/src/lib/secure_channel.c +0 -496
  539. data/src/lib/secure_channel.h +0 -43
  540. data/src/lib/stat.c +0 -248
  541. data/src/lib/stat.h +0 -51
  542. data/src/lib/tcp.h +0 -62
  543. data/src/lib/timer.c +0 -349
  544. data/src/lib/timer.h +0 -51
  545. data/src/lib/trema.c +0 -776
  546. data/src/lib/trema.h +0 -80
  547. data/src/lib/trema.hpp +0 -49
  548. data/src/lib/trema_private.c +0 -175
  549. data/src/lib/trema_private.h +0 -64
  550. data/src/lib/trema_wrapper.c +0 -59
  551. data/src/lib/trema_wrapper.h +0 -66
  552. data/src/lib/udp.h +0 -41
  553. data/src/lib/utility.c +0 -625
  554. data/src/lib/utility.h +0 -84
  555. data/src/lib/wrapper.c +0 -121
  556. data/src/lib/wrapper.h +0 -76
  557. data/src/management/application.c +0 -222
  558. data/src/management/echo.c +0 -183
  559. data/src/management/set_logging_level.c +0 -151
  560. data/src/management/show_stats.c +0 -148
  561. data/src/management/trema_manager +0 -184
  562. data/src/packetin_filter/README +0 -17
  563. data/src/packetin_filter/packetin_filter.c +0 -575
  564. data/src/switch_manager/README +0 -20
  565. data/src/switch_manager/cookie_table.c +0 -290
  566. data/src/switch_manager/cookie_table.h +0 -70
  567. data/src/switch_manager/dpid_table.c +0 -108
  568. data/src/switch_manager/dpid_table.h +0 -43
  569. data/src/switch_manager/event_forward_entry_manipulation.c +0 -120
  570. data/src/switch_manager/event_forward_entry_manipulation.h +0 -31
  571. data/src/switch_manager/ofpmsg_recv.c +0 -497
  572. data/src/switch_manager/ofpmsg_recv.h +0 -39
  573. data/src/switch_manager/ofpmsg_send.c +0 -274
  574. data/src/switch_manager/ofpmsg_send.h +0 -51
  575. data/src/switch_manager/secure_channel_listener.c +0 -296
  576. data/src/switch_manager/secure_channel_listener.h +0 -40
  577. data/src/switch_manager/secure_channel_receiver.c +0 -129
  578. data/src/switch_manager/secure_channel_receiver.h +0 -40
  579. data/src/switch_manager/secure_channel_sender.c +0 -131
  580. data/src/switch_manager/secure_channel_sender.h +0 -41
  581. data/src/switch_manager/service_interface.c +0 -180
  582. data/src/switch_manager/service_interface.h +0 -44
  583. data/src/switch_manager/switch.c +0 -988
  584. data/src/switch_manager/switch.h +0 -50
  585. data/src/switch_manager/switch_manager.c +0 -643
  586. data/src/switch_manager/switch_manager.h +0 -65
  587. data/src/switch_manager/switch_option.c +0 -30
  588. data/src/switch_manager/switch_option.h +0 -41
  589. data/src/switch_manager/switchinfo.h +0 -81
  590. data/src/switch_manager/xid_table.c +0 -182
  591. data/src/switch_manager/xid_table.h +0 -53
  592. data/src/tremashark/README +0 -79
  593. data/src/tremashark/packet_capture.c +0 -358
  594. data/src/tremashark/pcap_private.h +0 -45
  595. data/src/tremashark/pcap_queue.c +0 -195
  596. data/src/tremashark/pcap_queue.h +0 -56
  597. data/src/tremashark/plugin/.gitignore +0 -6
  598. data/src/tremashark/plugin/packet-trema/.gitignore +0 -5
  599. data/src/tremashark/plugin/packet-trema/Makefile +0 -77
  600. data/src/tremashark/plugin/packet-trema/Makefile.am +0 -110
  601. data/src/tremashark/plugin/packet-trema/Makefile.common +0 -29
  602. data/src/tremashark/plugin/packet-trema/moduleinfo.h +0 -39
  603. data/src/tremashark/plugin/packet-trema/packet-trema.c +0 -1671
  604. data/src/tremashark/plugin/packet-trema/plugin.c +0 -31
  605. data/src/tremashark/plugin/user_dlts +0 -2
  606. data/src/tremashark/queue.c +0 -167
  607. data/src/tremashark/queue.h +0 -58
  608. data/src/tremashark/stdin_relay.c +0 -257
  609. data/src/tremashark/syslog_relay.c +0 -247
  610. data/src/tremashark/tremashark.c +0 -554
  611. data/trema +0 -11
  612. data/trema-config +0 -11
  613. data/unittests/buffer_stubs.c +0 -72
  614. data/unittests/cmockery_trema.c +0 -121
  615. data/unittests/cmockery_trema.h +0 -95
  616. data/unittests/lib/buffer_test.c +0 -368
  617. data/unittests/lib/byteorder_test.c +0 -1798
  618. data/unittests/lib/daemon_test.c +0 -804
  619. data/unittests/lib/doubly_linked_list_test.c +0 -348
  620. data/unittests/lib/ether_test.c +0 -125
  621. data/unittests/lib/event_forward_interface_test.c +0 -1676
  622. data/unittests/lib/external_callback_test.c +0 -282
  623. data/unittests/lib/hash_table_test.c +0 -278
  624. data/unittests/lib/linked_list_test.c +0 -434
  625. data/unittests/lib/log_test.c +0 -672
  626. data/unittests/lib/management_interface_test.c +0 -238
  627. data/unittests/lib/management_service_interface_test.c +0 -317
  628. data/unittests/lib/match_table_test.c +0 -1507
  629. data/unittests/lib/message_queue_test.c +0 -381
  630. data/unittests/lib/messenger_test.c +0 -623
  631. data/unittests/lib/openflow_application_interface_test.c +0 -3713
  632. data/unittests/lib/openflow_message_test.c +0 -8047
  633. data/unittests/lib/packet_info_test.c +0 -558
  634. data/unittests/lib/packet_parser_test.c +0 -784
  635. data/unittests/lib/packetin_filter_interface_test.c +0 -721
  636. data/unittests/lib/persistent_storage_test.c +0 -800
  637. data/unittests/lib/stat_test.c +0 -433
  638. data/unittests/lib/test_packets/arp_rep.cap +0 -0
  639. data/unittests/lib/test_packets/arp_req.cap +0 -0
  640. data/unittests/lib/test_packets/icmp6_echo_rep.cap +0 -0
  641. data/unittests/lib/test_packets/icmp6_echo_req.cap +0 -0
  642. data/unittests/lib/test_packets/icmp_echo_rep.cap +0 -0
  643. data/unittests/lib/test_packets/icmp_echo_req.cap +0 -0
  644. data/unittests/lib/test_packets/igmp_query_v2.cap +0 -0
  645. data/unittests/lib/test_packets/ipx.cap +0 -0
  646. data/unittests/lib/test_packets/lldp.cap +0 -0
  647. data/unittests/lib/test_packets/lldp_over_ip.cap +0 -0
  648. data/unittests/lib/test_packets/rarp_req.cap +0 -0
  649. data/unittests/lib/test_packets/tcp.cap +0 -0
  650. data/unittests/lib/test_packets/tcp_syn.cap +0 -0
  651. data/unittests/lib/test_packets/udp.cap +0 -0
  652. data/unittests/lib/test_packets/udp_frag_head.cap +0 -0
  653. data/unittests/lib/test_packets/udp_frag_next.cap +0 -0
  654. data/unittests/lib/test_packets/vtag_icmp_echo_rep.cap +0 -0
  655. data/unittests/lib/test_packets/vtag_icmp_echo_req.cap +0 -0
  656. data/unittests/lib/timer_test.c +0 -246
  657. data/unittests/lib/trema_private_test.c +0 -321
  658. data/unittests/lib/trema_test.c +0 -1030
  659. data/unittests/lib/utility_test.c +0 -711
  660. data/unittests/lib/wrapper_test.c +0 -228
  661. data/unittests/packetin_filter/packetin_filter_test.c +0 -476
  662. data/unittests/switch_manager/switch_manager_test.c +0 -1183
  663. data/unittests/wrapper_stubs.c +0 -37
  664. data/vendor/.gitignore +0 -6
  665. data/vendor/README.md +0 -29
  666. data/vendor/cmockery-20110428.tar.gz +0 -0
  667. data/vendor/oflops-0.03.trema1.tar.gz +0 -0
  668. data/vendor/oflops_no_snmp+1.0.0.diff +0 -340
  669. data/vendor/openflow-1.0.0.tar.gz +0 -0
  670. data/vendor/openflow.git.tar.gz +0 -0
  671. data/vendor/openvswitch-1.2.2.trema1.tar.gz +0 -0
  672. data/vendor/openvswitch-1.2.2_librt-check.diff +0 -21
  673. data/vendor/packet-openflow.diff +0 -13
  674. data/vendor/ruby-ifconfig-1.2/COPYING +0 -340
  675. data/vendor/ruby-ifconfig-1.2/Changelog +0 -16
  676. data/vendor/ruby-ifconfig-1.2/INSTALL +0 -239
  677. data/vendor/ruby-ifconfig-1.2/README +0 -38
  678. data/vendor/ruby-ifconfig-1.2/Rakefile +0 -14
  679. data/vendor/ruby-ifconfig-1.2/TODO +0 -8
  680. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/darwin.txt +0 -17
  681. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/dragonflybsd.txt +0 -10
  682. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/dragonflybsd_netstat.txt +0 -14
  683. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/freebsd.txt +0 -17
  684. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/freebsd_netstat.txt +0 -24
  685. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/linux.txt +0 -60
  686. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/linux_ethernet.txt +0 -20
  687. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/netbsd.txt +0 -10
  688. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/openbsd.txt +0 -36
  689. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/sunos.txt +0 -10
  690. data/vendor/ruby-ifconfig-1.2/lib/ifconfig.rb +0 -71
  691. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/ifconfig.rb +0 -72
  692. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/interface_types.rb +0 -69
  693. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/network_types.rb +0 -3
  694. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/ifconfig.rb +0 -84
  695. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/interface_types.rb +0 -130
  696. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/network_types.rb +0 -49
  697. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/ifconfig.rb +0 -43
  698. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/interface_types.rb +0 -112
  699. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/network_types.rb +0 -55
  700. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/ifconfig.rb +0 -38
  701. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/interface_types.rb +0 -77
  702. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/network_types.rb +0 -4
  703. data/vendor/ruby-ifconfig-1.2/setup.rb +0 -1306
  704. data/vendor/ruby-ifconfig-1.2/test/test_bsd.rb +0 -35
  705. data/vendor/ruby-ifconfig-1.2/test/test_darwin.rb +0 -33
  706. data/vendor/ruby-ifconfig-1.2/test/test_dragonflybsd.rb +0 -35
  707. data/vendor/ruby-ifconfig-1.2/test/test_helper.rb +0 -4
  708. data/vendor/ruby-ifconfig-1.2/test/test_linux.rb +0 -31
  709. data/vendor/ruby-ifconfig-1.2/test/test_netbsd.rb +0 -33
  710. data/vendor/ruby-ifconfig-1.2/test/test_openbsd.rb +0 -33
  711. data/vendor/ruby-ifconfig-1.2/test/test_sunos.rb +0 -35
  712. data/vendor/ruby-ifconfig-1.2/test/unit/tc_darwin.rb +0 -40
  713. data/vendor/ruby-ifconfig-1.2/test/unit/tc_dragonflybsd.rb +0 -39
  714. data/vendor/ruby-ifconfig-1.2/test/unit/tc_freebsd.rb +0 -40
  715. data/vendor/ruby-ifconfig-1.2/test/unit/tc_linux.rb +0 -49
  716. data/vendor/ruby-ifconfig-1.2/test/unit/tc_netbsd.rb +0 -39
  717. data/vendor/ruby-ifconfig-1.2/test/unit/tc_openbsd.rb +0 -39
  718. data/vendor/ruby-ifconfig-1.2/test/unit/tc_sunos.rb +0 -44
@@ -1,800 +0,0 @@
1
- /*
2
- * Unit tests for persistent_storage.[ch]
3
- *
4
- * Copyright (C) 2008-2013 NEC Corporation
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License, version 2, as
8
- * published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along
16
- * with this program; if not, write to the Free Software Foundation, Inc.,
17
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
- */
19
-
20
-
21
- #include <errno.h>
22
- #include <sqlite3.h>
23
- #include <stdint.h>
24
- #include <stdio.h>
25
- #include <stdlib.h>
26
- #include <string.h>
27
- #include <unistd.h>
28
- #include "trema.h"
29
- #include "trema_private.h"
30
- #include "trema_wrapper.h"
31
- #include "cmockery_trema.h"
32
-
33
-
34
- /********************************************************************************
35
- * Mock functions.
36
- ********************************************************************************/
37
-
38
- static int ( *original_unlink )( const char *pathname );
39
- static void ( *original_error )( const char *format, ... );
40
-
41
- static int
42
- mock_unlink( const char *pathname ) {
43
- unlink( pathname );
44
- errno = ENOENT;
45
- return ( int ) mock();
46
- }
47
-
48
-
49
- static int
50
- mock_sqlite3_open( const char *filename, sqlite3 **ppDb ) {
51
- sqlite3_open( filename, ppDb );
52
- return ( int ) mock();
53
- }
54
-
55
-
56
- static int
57
- mock_sqlite3_close( sqlite3 *db ) {
58
- sqlite3_close( db );
59
- return ( int ) mock();
60
- }
61
-
62
-
63
- static char error_message[] = "ERROR";
64
-
65
- static int
66
- mock_sqlite3_exec( sqlite3 *db, const char *sql, int ( *callback )( void *, int, char **, char ** ), void *argument, char **errmsg ) {
67
- sqlite3_exec( db, sql, callback, argument, errmsg );
68
- *errmsg = error_message;
69
- return ( int ) mock();
70
- }
71
-
72
-
73
- static int
74
- mock_sqlite3_changes( sqlite3 *db ) {
75
- UNUSED( db );
76
- return ( int ) mock();
77
- }
78
-
79
-
80
- static const char *
81
- mock_sqlite3_errmsg( sqlite3 *db ) {
82
- UNUSED( db );
83
- return error_message;
84
- }
85
-
86
-
87
- static void
88
- mock_sqlite3_free( void *freed ) {
89
- UNUSED( freed );
90
- }
91
-
92
-
93
- static void
94
- mock_error( const char *format, ... ) {
95
- va_list args;
96
- va_start( args, format );
97
- char message[ 1000 ];
98
- vsprintf( message, format, args );
99
- va_end( args );
100
-
101
- check_expected( message );
102
- }
103
-
104
-
105
- /********************************************************************************
106
- * Setup and teardown functions.
107
- ********************************************************************************/
108
-
109
- static void
110
- setup() {
111
- setenv( "TREMA_TMP", "/tmp", 1 );
112
- set_trema_tmp();
113
- unlink( "/tmp/.trema.db" );
114
- original_error = error;
115
- error = mock_error;
116
- original_unlink = trema_unlink;
117
- trema_unlink = mock_unlink;
118
- }
119
-
120
-
121
- static void
122
- setup_and_init() {
123
- setup();
124
- init_persistent_storage();
125
- }
126
-
127
-
128
- static void
129
- teardown() {
130
- unsetenv( "TREMA_TMP" );
131
- unlink( "/tmp/.trema.db" );
132
- error = original_error;
133
- trema_unlink = original_unlink;
134
- }
135
-
136
-
137
- static void
138
- teardown_and_finalize() {
139
- teardown();
140
- finalize_persistent_storage();
141
- }
142
-
143
-
144
- /********************************************************************************
145
- * init_persistent_storage() tests.
146
- ********************************************************************************/
147
-
148
- static void
149
- test_init_persistent_storage_succeeds() {
150
- assert_true( init_persistent_storage() );
151
- assert_true( _get_backend_initialized() );
152
- assert_true( _get_db_file() != NULL );
153
- assert_true( _get_db_handle() != NULL );
154
-
155
- finalize_persistent_storage();
156
- }
157
-
158
-
159
- static void
160
- test_init_persistent_storage_fails_if_already_initialized() {
161
- init_persistent_storage();
162
-
163
- expect_string( mock_error, message, "Backend is already initialized." );
164
- assert_false( init_persistent_storage() );
165
-
166
- finalize_persistent_storage();
167
- }
168
-
169
-
170
- static void
171
- test_init_persistent_storage_fails_if_backend_is_not_opened() {
172
- void *original_sqlite3_open = trema_sqlite3_open;
173
- trema_sqlite3_open = mock_sqlite3_open;
174
- void *original_sqlite3_errmsg = trema_sqlite3_errmsg;
175
- trema_sqlite3_errmsg = mock_sqlite3_errmsg;
176
-
177
- will_return( mock_sqlite3_open, SQLITE_ERROR );
178
- expect_string( mock_error, message, "Failed to open backend database ( ERROR )." );
179
- assert_false( init_persistent_storage() );
180
- assert_false( _get_backend_initialized() );
181
- assert_true( _get_db_file() == NULL );
182
- assert_true( _get_db_handle() == NULL );
183
-
184
- trema_sqlite3_open = original_sqlite3_open;
185
- trema_sqlite3_errmsg = original_sqlite3_errmsg;
186
- }
187
-
188
-
189
- static void
190
- test_init_persistent_storage_fails_if_backend_db_is_not_created() {
191
- void *original_sqlite3_exec = trema_sqlite3_exec;
192
- trema_sqlite3_exec = mock_sqlite3_exec;
193
- void *original_sqlite3_free = trema_sqlite3_free;
194
- trema_sqlite3_free = mock_sqlite3_free;
195
-
196
- will_return( mock_sqlite3_exec, SQLITE_ERROR );
197
- expect_string( mock_error, message, "Failed to create a table ( error = ERROR )." );
198
- assert_false( init_persistent_storage() );
199
- assert_false( _get_backend_initialized() );
200
- assert_true( _get_db_file() == NULL );
201
- assert_true( _get_db_handle() == NULL );
202
-
203
- trema_sqlite3_exec = original_sqlite3_exec;
204
- trema_sqlite3_free = original_sqlite3_free;
205
- }
206
-
207
-
208
- /********************************************************************************
209
- * finalize_persistent_storage() tests.
210
- ********************************************************************************/
211
-
212
- static void
213
- test_finalize_persistent_storage_succeeds() {
214
- init_persistent_storage();
215
-
216
- assert_true( finalize_persistent_storage() );
217
- assert_false( _get_backend_initialized() );
218
- assert_true( _get_db_file() == NULL );
219
- assert_true( _get_db_handle() == NULL );
220
- }
221
-
222
-
223
- static void
224
- test_finalize_persistent_storage_fails_if_not_initialized() {
225
- expect_string( mock_error, message, "Backend is not initialized yet." );
226
- assert_false( finalize_persistent_storage() );
227
- }
228
-
229
-
230
- static void
231
- test_finalize_persistent_storage_fails_if_backend_is_not_closed() {
232
- init_persistent_storage();
233
-
234
- void *original_sqlite3_close = trema_sqlite3_close;
235
- trema_sqlite3_close = mock_sqlite3_close;
236
- void *original_sqlite3_errmsg = trema_sqlite3_errmsg;
237
- trema_sqlite3_errmsg = mock_sqlite3_errmsg;
238
-
239
- will_return( mock_sqlite3_close, SQLITE_ERROR );
240
- expect_string( mock_error, message, "Failed to destroy a sqlite3 object ( ERROR )." );
241
- assert_false( finalize_persistent_storage() );
242
- assert_false( _get_backend_initialized() );
243
- assert_true( _get_db_file() == NULL );
244
- assert_true( _get_db_handle() == NULL );
245
-
246
- trema_sqlite3_close = original_sqlite3_close;
247
- trema_sqlite3_errmsg = original_sqlite3_errmsg;
248
- }
249
-
250
-
251
- /********************************************************************************
252
- * clear_persistent_storage() tests.
253
- ********************************************************************************/
254
-
255
- static void
256
- test_clear_persistent_storage_succeeds() {
257
- init_persistent_storage();
258
-
259
- set_value( "KEY", "VALUE" );
260
-
261
- will_return( mock_unlink, 0 );
262
- assert_true( clear_persistent_storage() );
263
- assert_true( set_value( "NEW_KEY", "NEW_VALUE" ) );
264
- char buf[ 256 ];
265
- expect_string( mock_error, message, "Failed to retrieve a value for 'KEY'." );
266
- assert_false( get_value( "KEY", buf, sizeof( buf ) ) );
267
- assert_true( get_value( "NEW_KEY", buf, sizeof( buf ) ) );
268
- assert_string_equal( "NEW_VALUE", buf );
269
-
270
- finalize_persistent_storage();
271
- }
272
-
273
-
274
- static void
275
- test_clear_persistent_storage_fails_if_not_initialized() {
276
- expect_string( mock_error, message, "Backend is not initialized yet." );
277
- assert_false( clear_persistent_storage() );
278
- }
279
-
280
-
281
- static void
282
- test_clear_persistent_storage_fails_if_unlink_fails() {
283
- init_persistent_storage();
284
-
285
- set_value( "KEY", "VALUE" );
286
-
287
- will_return( mock_unlink, -1 );
288
- expect_string( mock_error, message, "Failed to delete database file. ( db_file = /tmp/.trema.db, errno = No such file or directory [2] )." );
289
- assert_false( clear_persistent_storage() );
290
- }
291
-
292
-
293
- /********************************************************************************
294
- * set_value() tests.
295
- ********************************************************************************/
296
-
297
- static void
298
- test_set_value_succeeds() {
299
- assert_true( set_value( "KEY", "VALUE" ) );
300
- assert_true( set_value( "KEY2", "VALUE2" ) );
301
- }
302
-
303
-
304
- static void
305
- test_set_value_updates_value() {
306
- set_value( "KEY", "VALUE" );
307
-
308
- assert_true( set_value( "KEY", "NEW_VALUE" ) );
309
- char buf[ 256 ];
310
- assert_true( get_value( "KEY", buf, sizeof( buf ) ) );
311
- assert_string_equal( "NEW_VALUE", buf );
312
- }
313
-
314
-
315
- static void
316
- test_set_value_clears_value() {
317
- set_value( "KEY", "VALUE" );
318
-
319
- assert_true( set_value( "KEY", "" ) );
320
- char buf[ 256 ];
321
- assert_true( get_value( "KEY", buf, sizeof( buf ) ) );
322
- assert_string_equal( "", buf );
323
- }
324
-
325
-
326
- static void
327
- test_set_value_fails_with_too_long_key() {
328
- size_t key_length = _get_max_key_length() + 1;
329
- char *key = xmalloc( key_length + 1 );
330
- memset( key, 'a', key_length );
331
- key[ key_length ] = '\0';
332
- char *expected_error = xasprintf( "Too long key ( length = %u ) specified. Maximum length is %u.",
333
- key_length, _get_max_key_length() );
334
-
335
- expect_string( mock_error, message, expected_error );
336
- assert_false( set_value( key, "VALUE" ) );
337
-
338
- xfree( key );
339
- xfree( expected_error );
340
- }
341
-
342
-
343
- static void
344
- test_set_value_fails_with_too_long_value() {
345
- size_t value_length = _get_max_value_length() + 1;
346
- char *value = xmalloc( value_length + 1 );
347
- memset( value, 'a', value_length );
348
- value[ value_length ] = '\0';
349
- char *expected_error = xasprintf( "Too long value ( length = %u ) specified. Maximum length is %u.",
350
- value_length, _get_max_value_length() );
351
-
352
- expect_string( mock_error, message, expected_error );
353
- assert_false( set_value( "KEY", value ) );
354
-
355
- xfree( value );
356
- xfree( expected_error );
357
- }
358
-
359
-
360
- static void
361
- test_set_value_fails_with_NULL_key() {
362
- expect_string( mock_error, message, "'key' must be specified." );
363
- assert_false( set_value( NULL, "VALUE" ) );
364
- }
365
-
366
-
367
- static void
368
- test_set_value_fails_with_NULL_value() {
369
- expect_string( mock_error, message, "'value' must be specified." );
370
- assert_false( set_value( "KEY", NULL ) );
371
- }
372
-
373
-
374
- static void
375
- test_set_value_fails_with_invalid_characters() {
376
- const char invalid_characters[] = { ( char ) 0x7f, ( char ) 0x1f, ( char ) 0xff, ( char ) 0x00 };
377
- expect_string( mock_error, message, "'key' must only have printable ASCII characters." );
378
- assert_false( set_value( invalid_characters, "VALUE" ) );
379
- expect_string( mock_error, message, "'value' must only have printable ASCII characters." );
380
- assert_false( set_value( "KEY", invalid_characters ) );
381
- }
382
-
383
-
384
- static void
385
- test_set_value_fails_if_not_initialized() {
386
- expect_string( mock_error, message, "Backend is not initialized yet." );
387
- assert_false( set_value( "KEY", "VALUE" ) );
388
- }
389
-
390
-
391
- static void
392
- test_set_value_escapes_string() {
393
- assert_true( set_value( "THIS \"IS\", A, 'KEY'", "HERE \"IS\", A, 'VALULE'" ) );
394
- char buf[ 256 ];
395
- assert_true( get_value( "THIS \"IS\", A, 'KEY'", buf, sizeof( buf ) ) );
396
- assert_string_equal( "HERE \"IS\", A, 'VALULE'", buf );
397
-
398
- assert_true( set_value( "THIS \"IS\", A, 'KEY'", "HERE \"IS\", A, 'NEW_VALULE'" ) );
399
- assert_true( get_value( "THIS \"IS\", A, 'KEY'", buf, sizeof( buf ) ) );
400
- assert_string_equal( "HERE \"IS\", A, 'NEW_VALULE'", buf );
401
- }
402
-
403
-
404
- static void
405
- test_set_value_avoids_injection_attacks() {
406
- assert_true( set_value( "KEY', 'VALUE'); DROP TABLE trema;", "VALUE" ) );
407
- char buf[ 256 ];
408
- assert_true( get_value( "KEY', 'VALUE'); DROP TABLE trema;", buf, sizeof( buf ) ) );
409
- assert_string_equal( "VALUE", buf );
410
-
411
- assert_true( set_value( "KEY", "VALUE'); DROP TABLE trema;" ) );
412
- assert_true( get_value( "KEY", buf, sizeof( buf ) ) );
413
- assert_string_equal( "VALUE'); DROP TABLE trema;", buf );
414
-
415
- assert_true( set_value( "KEY'; DROP TABLE trema;", "NEW_VALUE" ) );
416
- assert_true( get_value( "KEY", buf, sizeof( buf ) ) );
417
- assert_string_equal( "VALUE'); DROP TABLE trema;", buf );
418
-
419
- assert_true( set_value( "KEY", "NEW_VALUE' WHERE KEY = 'KEY'; DROP TABLE trema;" ) );
420
- assert_true( get_value( "KEY", buf, sizeof( buf ) ) );
421
- assert_string_equal( "NEW_VALUE' WHERE KEY = 'KEY'; DROP TABLE trema;", buf );
422
- }
423
-
424
-
425
- static void
426
- test_set_value_fails_if_backend_fails_to_store_key_value() {
427
- void *original_sqlite3_exec = trema_sqlite3_exec;
428
- trema_sqlite3_exec = mock_sqlite3_exec;
429
- void *original_sqlite3_free = trema_sqlite3_free;
430
- trema_sqlite3_free = mock_sqlite3_free;
431
- void *original_sqlite3_changes = trema_sqlite3_changes;
432
- trema_sqlite3_changes = mock_sqlite3_changes;
433
-
434
- will_return( mock_sqlite3_exec, SQLITE_OK );
435
- will_return( mock_sqlite3_exec, SQLITE_ERROR );
436
- expect_string( mock_error, message, "Failed to execute a SQL statement ( statement = INSERT INTO trema (key,value) VALUES ('KEY','VALUE'), error = ERROR )." );
437
- assert_false( set_value( "KEY", "VALUE" ) );
438
-
439
- will_return( mock_sqlite3_exec, SQLITE_OK );
440
- will_return( mock_sqlite3_exec, SQLITE_OK );
441
- will_return( mock_sqlite3_changes, 1 );
442
- delete_key_value( "KEY" );
443
-
444
- will_return( mock_sqlite3_exec, SQLITE_OK );
445
- will_return( mock_sqlite3_exec, SQLITE_OK );
446
- will_return( mock_sqlite3_changes, 2 );
447
- expect_string( mock_error, message, "Multiple entries are created ( n_changes = 2 )." );
448
- assert_false( set_value( "KEY", "VALUE" ) );
449
-
450
- will_return( mock_sqlite3_exec, SQLITE_OK );
451
- will_return( mock_sqlite3_exec, SQLITE_OK );
452
- will_return( mock_sqlite3_changes, 1 );
453
- delete_key_value( "KEY" );
454
-
455
- will_return( mock_sqlite3_exec, SQLITE_OK );
456
- will_return( mock_sqlite3_exec, SQLITE_OK );
457
- will_return( mock_sqlite3_changes, 0 );
458
- assert_false( set_value( "KEY", "VALUE" ) );
459
-
460
- will_return( mock_sqlite3_exec, SQLITE_OK );
461
- will_return( mock_sqlite3_exec, SQLITE_ERROR );
462
- expect_string( mock_error, message, "Failed to execute a SQL statement ( statement = UPDATE trema SET value = 'NEW_VALUE' WHERE key = 'KEY', error = ERROR )." );
463
- assert_false( set_value( "KEY", "NEW_VALUE" ) );
464
-
465
- will_return( mock_sqlite3_exec, SQLITE_OK );
466
- will_return( mock_sqlite3_exec, SQLITE_OK );
467
- will_return( mock_sqlite3_changes, 0 );
468
- assert_false( set_value( "KEY", "NEW_VALUE" ) );
469
-
470
- will_return( mock_sqlite3_exec, SQLITE_OK );
471
- will_return( mock_sqlite3_exec, SQLITE_OK );
472
- will_return( mock_sqlite3_changes, 2 );
473
- expect_string( mock_error, message, "Multiple entries are updated ( n_changes = 2 )." );
474
- assert_false( set_value( "KEY", "NEW_VALUE" ) );
475
-
476
- trema_sqlite3_exec = original_sqlite3_exec;
477
- trema_sqlite3_free = original_sqlite3_free;
478
- trema_sqlite3_changes = original_sqlite3_changes;
479
- }
480
-
481
-
482
- /********************************************************************************
483
- * get_value() tests.
484
- ********************************************************************************/
485
-
486
- static void
487
- test_get_value_succeeds() {
488
- set_value( "KEY1", "VALUE1" );
489
- set_value( "KEY2", "VALUE2" );
490
-
491
- char buf[ 256 ];
492
- assert_true( get_value( "KEY1", buf, sizeof( buf ) ) );
493
- assert_string_equal( "VALUE1", buf );
494
- assert_true( get_value( "KEY2", buf, sizeof( buf ) ) );
495
- assert_string_equal( "VALUE2", buf );
496
- }
497
-
498
-
499
- static void
500
- test_get_value_fails_with_undefined_key() {
501
- char buf[ 256 ];
502
- expect_string( mock_error, message, "Failed to retrieve a value for 'UNDEFINED_KEY'." );
503
- assert_false( get_value( "UNDEFINED_KEY", buf, sizeof( buf ) ) );
504
- }
505
-
506
-
507
- static void
508
- test_get_value_fails_with_too_long_key() {
509
- size_t key_length = _get_max_key_length() + 1;
510
- char *key = xmalloc( key_length + 1 );
511
- memset( key, 'a', key_length );
512
- key[ key_length ] = '\0';
513
- char *expected_error = xasprintf( "Too long key ( length = %u ) specified. Maximum length is %u.",
514
- key_length, _get_max_key_length() );
515
-
516
- expect_string( mock_error, message, expected_error );
517
- char buf[ 256 ];
518
- assert_false( get_value( key, buf, sizeof( buf ) ) );
519
-
520
- xfree( key );
521
- xfree( expected_error );
522
- }
523
-
524
-
525
- static void
526
- test_get_value_fails_with_insufficient_buffer() {
527
- set_value( "KEY", "VALUE" );
528
-
529
- expect_string( mock_error, message, "'length' must be greater than zero." );
530
- char buf[ 1 ];
531
- assert_false( get_value( "KEY", buf, 0 ) );
532
- expect_string( mock_error, message, "Insufficient buffer space ( 6 [bytes] > 1 [bytes] )." );
533
- assert_false( get_value( "KEY", buf, sizeof( buf ) ) );
534
- }
535
-
536
-
537
- static void
538
- test_get_value_fails_with_NULL_key() {
539
- char buf[ 256 ];
540
- expect_string( mock_error, message, "'key' must be specified." );
541
- assert_false( get_value( NULL, buf, sizeof( buf ) ) );
542
- }
543
-
544
-
545
- static void
546
- test_get_value_fails_with_NULL_value() {
547
- expect_string( mock_error, message, "'value' must be specified." );
548
- assert_false( get_value( "KEY", NULL, 128 ) );
549
- }
550
-
551
-
552
- static void
553
- test_get_value_fails_with_invalid_characters() {
554
- const char invalid_characters[] = { ( char ) 0x7f, ( char ) 0x1f, ( char ) 0xff, ( char ) 0x00 };
555
- expect_string( mock_error, message, "'key' must only have printable ASCII characters." );
556
- char buf[ 256 ];
557
- assert_false( get_value( invalid_characters, buf, sizeof( buf ) ) );
558
- }
559
-
560
-
561
- static void
562
- test_get_value_fails_if_not_initialized() {
563
- char buf[ 256 ];
564
- expect_string( mock_error, message, "Backend is not initialized yet." );
565
- assert_false( get_value( "KEY", buf, sizeof( buf ) ) );
566
- }
567
-
568
-
569
- static void
570
- test_get_value_escapes_string() {
571
- set_value( "THIS \"IS\", A, 'KEY'", "VALUE" );
572
-
573
- char buf[ 256 ];
574
- assert_true( get_value( "THIS \"IS\", A, 'KEY'", buf, sizeof( buf ) ) );
575
- assert_string_equal( "VALUE", buf );
576
- }
577
-
578
-
579
- static void
580
- test_get_value_avoids_injection_attacks() {
581
- set_value( "KEY", "VALUE" );
582
-
583
- char buf[ 256 ];
584
- expect_string( mock_error, message, "Failed to retrieve a value for 'KEY'; DROP TABLE trema;'." );
585
- assert_false( get_value( "KEY'; DROP TABLE trema;", buf, sizeof( buf ) ) );
586
- assert_true( get_value( "KEY", buf, sizeof( buf ) ) );
587
- assert_string_equal( "VALUE", buf );
588
- }
589
-
590
-
591
- static void
592
- test_get_value_fails_if_backend_fails_to_lookup_value() {
593
- void *original_sqlite3_exec = trema_sqlite3_exec;
594
- trema_sqlite3_exec = mock_sqlite3_exec;
595
- void *original_sqlite3_free = trema_sqlite3_free;
596
- trema_sqlite3_free = mock_sqlite3_free;
597
-
598
- will_return( mock_sqlite3_exec, SQLITE_ERROR );
599
- expect_string( mock_error, message, "Failed to execute a SQL statement ( statement = SELECT value FROM trema WHERE key = 'KEY', error = ERROR )." );
600
- expect_string( mock_error, message, "Failed to retrieve a value for 'KEY'." );
601
- char buf[ 256 ];
602
- assert_false( get_value( "KEY", buf, sizeof( buf ) ) );
603
-
604
- trema_sqlite3_exec = original_sqlite3_exec;
605
- trema_sqlite3_free = original_sqlite3_free;
606
- }
607
-
608
-
609
-
610
- /********************************************************************************
611
- * delete_key_value() tests.
612
- ********************************************************************************/
613
-
614
- static void
615
- test_delete_key_value_succeeds() {
616
- const char *key = "KEY";
617
- const char *value = "VALUE";
618
-
619
- set_value( key, value );
620
-
621
- assert_true( delete_key_value( key ) );
622
- expect_string( mock_error, message, "Failed to retrieve a value for 'KEY'." );
623
- char buf[ 256 ];
624
- assert_false( get_value( key, buf, sizeof( buf ) ) );
625
- }
626
-
627
-
628
- static void
629
- test_delete_key_value_fails_with_undefined_key() {
630
- expect_string( mock_error, message, "An entry for 'UNDEFINED_KEY' does not exist." );
631
- assert_false( delete_key_value( "UNDEFINED_KEY" ) );
632
- }
633
-
634
-
635
- static void
636
- test_delete_key_value_fails_with_too_long_key() {
637
- size_t key_length = _get_max_key_length() + 1;
638
- char *key = xmalloc( key_length + 1 );
639
- memset( key, 'a', key_length );
640
- key[ key_length ] = '\0';
641
- char *expected_error = xasprintf( "Too long key ( length = %u ) specified. Maximum length is %u.",
642
- key_length, _get_max_key_length() );
643
-
644
- expect_string( mock_error, message, expected_error );
645
- assert_false( delete_key_value( key ) );
646
-
647
- xfree( key );
648
- xfree( expected_error );
649
- }
650
-
651
-
652
- static void
653
- test_delete_key_value_fails_with_NULL_key() {
654
- expect_string( mock_error, message, "'key' must be specified." );
655
- assert_false( delete_key_value( NULL ) );
656
- }
657
-
658
-
659
- static void
660
- test_delete_key_value_fails_with_invalid_characters() {
661
- const char invalid_characters[] = { ( char ) 0x7f, ( char ) 0x1f, ( char ) 0xff, ( char ) 0x00 };
662
- expect_string( mock_error, message, "'key' must only have printable ASCII characters." );
663
- assert_false( delete_key_value( invalid_characters ) );
664
- }
665
-
666
-
667
- static void
668
- test_delete_key_value_fails_if_not_initialized() {
669
- expect_string( mock_error, message, "Backend is not initialized yet." );
670
- assert_false( delete_key_value( "KEY" ) );
671
- }
672
-
673
-
674
- static void
675
- test_delete_key_value_escapes_string() {
676
- set_value( "THIS \"IS\", A, 'KEY'", "VALUE" );
677
-
678
- assert_true( delete_key_value( "THIS \"IS\", A, 'KEY'" ) );
679
- expect_string( mock_error, message, "Failed to retrieve a value for 'THIS \"IS\", A, 'KEY''." );
680
- char buf[ 256 ];
681
- assert_false( get_value( "THIS \"IS\", A, 'KEY'", buf, sizeof( buf ) ) );
682
- }
683
-
684
-
685
- static void
686
- test_delete_key_value_avoids_injection_attacks() {
687
- set_value( "KEY", "VALUE" );
688
-
689
- expect_string( mock_error, message, "An entry for 'KEY'; DROP TABLE trema;' does not exist." );
690
- assert_false( delete_key_value( "KEY'; DROP TABLE trema;" ) );
691
- char buf[ 256 ];
692
- assert_true( get_value( "KEY", buf, sizeof( buf ) ) );
693
- assert_string_equal( "VALUE", buf );
694
- }
695
-
696
-
697
- static void
698
- test_delete_key_value_fails_if_backend_fails_to_delete_key_value() {
699
- set_value( "KEY", "VALUE" );
700
- void *original_sqlite3_exec = trema_sqlite3_exec;
701
- trema_sqlite3_exec = mock_sqlite3_exec;
702
- void *original_sqlite3_free = trema_sqlite3_free;
703
- trema_sqlite3_free = mock_sqlite3_free;
704
-
705
- will_return( mock_sqlite3_exec, SQLITE_OK );
706
- will_return( mock_sqlite3_exec, SQLITE_ERROR );
707
- expect_string( mock_error, message, "Failed to execute a SQL statement ( statement = DELETE FROM trema WHERE key = 'KEY', error = ERROR )." );
708
- assert_false( delete_key_value( "KEY" ) );
709
-
710
- trema_sqlite3_exec = original_sqlite3_exec;
711
- trema_sqlite3_free = original_sqlite3_free;
712
- }
713
-
714
-
715
- static void
716
- test_delete_key_value_fails_if_backend_deletes_multiple_key_values() {
717
- set_value( "KEY", "VALUE" );
718
- void *original_sqlite3_changes = trema_sqlite3_changes;
719
- trema_sqlite3_changes = mock_sqlite3_changes;
720
-
721
- will_return( mock_sqlite3_changes, 2 );
722
- expect_string( mock_error, message, "Multiple entries are deleted ( n_changes = 2 )." );
723
- assert_false( delete_key_value( "KEY" ) );
724
-
725
- trema_sqlite3_changes = original_sqlite3_changes;
726
- }
727
-
728
-
729
- /********************************************************************************
730
- * Run tests.
731
- ********************************************************************************/
732
-
733
- int
734
- main() {
735
- const UnitTest tests[] = {
736
- // init_persistent_storage() tests.
737
- unit_test_setup_teardown( test_init_persistent_storage_succeeds, setup, teardown ),
738
- unit_test_setup_teardown( test_init_persistent_storage_fails_if_already_initialized, setup, teardown ),
739
- unit_test_setup_teardown( test_init_persistent_storage_fails_if_backend_is_not_opened, setup, teardown ),
740
- unit_test_setup_teardown( test_init_persistent_storage_fails_if_backend_db_is_not_created, setup, teardown ),
741
-
742
- // finalize_persistent_storage() tests.
743
- unit_test_setup_teardown( test_finalize_persistent_storage_succeeds, setup, teardown ),
744
- unit_test_setup_teardown( test_finalize_persistent_storage_fails_if_not_initialized, setup, teardown ),
745
- unit_test_setup_teardown( test_finalize_persistent_storage_fails_if_backend_is_not_closed, setup, teardown ),
746
-
747
- // clear_persistent_storage() tests.
748
- unit_test_setup_teardown( test_clear_persistent_storage_succeeds, setup, teardown ),
749
- unit_test_setup_teardown( test_clear_persistent_storage_fails_if_not_initialized, setup, teardown ),
750
- unit_test_setup_teardown( test_clear_persistent_storage_fails_if_unlink_fails, setup, teardown ),
751
-
752
- // set_value() tests.
753
- unit_test_setup_teardown( test_set_value_succeeds, setup_and_init, teardown_and_finalize ),
754
- unit_test_setup_teardown( test_set_value_updates_value, setup_and_init, teardown_and_finalize ),
755
- unit_test_setup_teardown( test_set_value_clears_value, setup_and_init, teardown_and_finalize ),
756
- unit_test_setup_teardown( test_set_value_fails_with_too_long_key, setup_and_init, teardown_and_finalize ),
757
- unit_test_setup_teardown( test_set_value_fails_with_too_long_value, setup_and_init, teardown_and_finalize ),
758
- unit_test_setup_teardown( test_set_value_fails_with_NULL_key, setup_and_init, teardown_and_finalize ),
759
- unit_test_setup_teardown( test_set_value_fails_with_NULL_value, setup_and_init, teardown_and_finalize ),
760
- unit_test_setup_teardown( test_set_value_fails_with_invalid_characters, setup_and_init, teardown_and_finalize ),
761
- unit_test_setup_teardown( test_set_value_fails_if_not_initialized, setup, teardown ),
762
- unit_test_setup_teardown( test_set_value_escapes_string, setup_and_init, teardown_and_finalize ),
763
- unit_test_setup_teardown( test_set_value_avoids_injection_attacks, setup_and_init, teardown_and_finalize ),
764
- unit_test_setup_teardown( test_set_value_fails_if_backend_fails_to_store_key_value, setup_and_init, teardown_and_finalize ),
765
-
766
- // get_value() tests.
767
- unit_test_setup_teardown( test_get_value_succeeds, setup_and_init, teardown_and_finalize ),
768
- unit_test_setup_teardown( test_get_value_fails_with_undefined_key, setup_and_init, teardown_and_finalize ),
769
- unit_test_setup_teardown( test_get_value_fails_with_too_long_key, setup_and_init, teardown_and_finalize ),
770
- unit_test_setup_teardown( test_get_value_fails_with_insufficient_buffer, setup_and_init, teardown_and_finalize ),
771
- unit_test_setup_teardown( test_get_value_fails_with_NULL_key, setup_and_init, teardown_and_finalize ),
772
- unit_test_setup_teardown( test_get_value_fails_with_NULL_value, setup_and_init, teardown_and_finalize ),
773
- unit_test_setup_teardown( test_get_value_fails_with_invalid_characters, setup_and_init, teardown_and_finalize ),
774
- unit_test_setup_teardown( test_get_value_fails_if_not_initialized, setup, teardown ),
775
- unit_test_setup_teardown( test_get_value_escapes_string, setup_and_init, teardown_and_finalize ),
776
- unit_test_setup_teardown( test_get_value_avoids_injection_attacks, setup_and_init, teardown_and_finalize ),
777
- unit_test_setup_teardown( test_get_value_fails_if_backend_fails_to_lookup_value, setup_and_init, teardown_and_finalize ),
778
-
779
- // delete_key_value() tests.
780
- unit_test_setup_teardown( test_delete_key_value_succeeds, setup_and_init, teardown_and_finalize ),
781
- unit_test_setup_teardown( test_delete_key_value_fails_with_undefined_key, setup_and_init, teardown_and_finalize ),
782
- unit_test_setup_teardown( test_delete_key_value_fails_with_too_long_key, setup_and_init, teardown_and_finalize ),
783
- unit_test_setup_teardown( test_delete_key_value_fails_with_NULL_key, setup_and_init, teardown_and_finalize ),
784
- unit_test_setup_teardown( test_delete_key_value_fails_with_invalid_characters, setup_and_init, teardown_and_finalize ),
785
- unit_test_setup_teardown( test_delete_key_value_fails_if_not_initialized, setup, teardown ),
786
- unit_test_setup_teardown( test_delete_key_value_escapes_string, setup_and_init, teardown_and_finalize ),
787
- unit_test_setup_teardown( test_delete_key_value_avoids_injection_attacks, setup_and_init, teardown_and_finalize ),
788
- unit_test_setup_teardown( test_delete_key_value_fails_if_backend_fails_to_delete_key_value, setup_and_init, teardown_and_finalize ),
789
- unit_test_setup_teardown( test_delete_key_value_fails_if_backend_deletes_multiple_key_values, setup_and_init, teardown_and_finalize ),
790
- };
791
- return run_tests( tests );
792
- }
793
-
794
-
795
- /*
796
- * Local variables:
797
- * c-basic-offset: 2
798
- * indent-tabs-mode: nil
799
- * End:
800
- */