Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
as0ler authored and trufae committed Dec 17, 2020
1 parent 5acdbee commit 4c708a7
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions python/test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ def setUpClass(cls):
cls.curdir = os.path.dirname(os.path.realpath(__file__))

def setUp(self):
self.r2 = r2pipe.open(os.path.join(self.curdir, "ls") , ["-2"])
self.r2_ls = r2pipe.open(os.path.join(self.curdir, "ls") , ["-2"])
self.r2 = r2pipe.open("-")

def tearDown(self):
self.r2_ls.quit()
self.r2.quit()

def test_open_successfully(self):
Expand All @@ -27,15 +29,20 @@ def test_open_unsuccessfully_file(self):
def test_open_unsuccessfully_url(self):
with self.assertRaises(Exception):
r2 = r2pipe.open("404://notfound")

def test_open_successfully_with_params(self):
r2 = r2pipe.open(os.path.join(self.curdir, "ls") , ["-nn"])
res = r2.cmd('pxW 4~:0[1]').strip()
self.assertEqual(res, "0xfeedfacf")

def test_r2cmd_successfully(self):
self.r2.cmd("aa")
res = self.r2.cmd("pi 1").strip()
self.r2_ls.cmd("aa")
res = self.r2_ls.cmd("pi 1").strip()
self.assertEqual(res, "push rbp")

def test_r2cmd_json_successfully(self):
self.r2.cmd("aa")
res = self.r2.cmdj("pij 1")
self.r2_ls.cmd("aa")
res = self.r2_ls.cmdj("pij 1")
self.assertIsInstance(res[0], dict)
self.assertEqual(res[0]['opcode'], "push rbp")

Expand All @@ -44,3 +51,40 @@ def test_r2ccal_successfully(self):
res = r2.cmd("pi 1 @e:scr.color=0").strip()
self.assertEqual(res, "push rbp")
r2.quit()

def test_r2cmd_hello_newline(self):
cmd = "?e hello\n"
expected = "hello\n"
res = self.r2.cmd(cmd)
self.assertEqual(res, expected)

def test_r2cmd_hello_world_newline(self):
cmd = "?e hello\n?e world"
expected = "hello\nworld\n"
res = self.r2.cmd(cmd)
self.assertEqual(res, expected)

def test_r2cmd_hello_world(self):
cmd = "?e hello;?e world"
expected = "hello\nworld\n"
res = self.r2.cmd(cmd)
self.assertEqual(res, expected)

def test_r2cmd_hello_world(self):
cmd = "?e hello;?e world"
expected = "hello\nworld\n"
res = self.r2.cmd(cmd)
self.assertEqual(res, expected)

def test_r2cmd_hello_world_multiple_newlines(self):
cmd = "?e hello\n\n;\n\n?e world"
expected = "hello\nworld\n"
res = self.r2.cmd(cmd)
self.assertEqual(res, expected)

def test_r2cmd_hello_world_multiple_semicolon(self):
cmd = "?e hello;;;;;?e world"
expected = "hello\nworld\n"
res = self.r2.cmd(cmd)
self.assertEqual(res, expected)

0 comments on commit 4c708a7

Please sign in to comment.