def test_plot_to_file_dynamic_size(self): dpi = 72 ratio = 50 file_0_size = os.path.getsize(self.test_file) file_1_size = os.path.getsize(self.test_medium_binary_src) width_0 = file_0_size / ratio width_1 = file_1_size / ratio height = 800 temp_dir = tempfile.gettempdir() # temp_dir = self.test_file_dir img_0_path = os.path.join(temp_dir, 'CAT-tptfds-test-small.png') img_1_path = os.path.join(temp_dir, 'CAT-tptfds-test-med.png') expected_0_size = (int(dpi * width_0 / PlotBase.DEFAULT_DPI), int(dpi * height / PlotBase.DEFAULT_DPI)) expected_1_size = (int(dpi * width_1 / PlotBase.DEFAULT_DPI), int(dpi * height / PlotBase.DEFAULT_DPI)) cad = CodescannerAnalysisData(self.test_file) cad.plot_to_dynamic_size_file(str(img_0_path), dpi, width_0, height) cad = CodescannerAnalysisData(self.test_medium_binary_src) cad.plot_to_dynamic_size_file(str(img_1_path), dpi, width_1, height) assert os.path.isfile(img_0_path) assert os.path.isfile(img_1_path) # print("expected_0_size: %s" % str(expected_0_size)) # print("expected_1_size: %s" % str(expected_1_size)) helper.assert_image_size(expected_0_size, str(img_0_path)) helper.assert_image_size(expected_1_size, str(img_1_path)) os.remove(img_0_path) os.remove(img_1_path)
def test_plot_to_dynamic_size_real_file(self): dpi = 72 height = 800 temp_dir = tempfile.gettempdir() # temp_dir = self.test_file_dir bin_0_src = self.test_binary_src bin_1_src = self.test_medium_binary_src img_0_path = os.path.join(temp_dir, 'CMT-tptdsf2-small.png') img_1_path = os.path.join(temp_dir, 'CMT-tptdsf2-medium.png') file_0_size = os.path.getsize(bin_0_src) / 50 file_1_size = os.path.getsize(bin_1_src) / 50 expected_0_size = (int(dpi * file_0_size / PlotBase.DEFAULT_DPI), int(dpi * height / PlotBase.DEFAULT_DPI)) expected_1_size = (int(dpi * file_1_size / PlotBase.DEFAULT_DPI), int(dpi * height / PlotBase.DEFAULT_DPI)) r_0 = helper.extract_regions(bin_0_src) r_1 = helper.extract_regions(bin_1_src) cm_0 = ColorMap(bin_0_src, r_0) cm_1 = ColorMap(bin_1_src, r_1) cm_0.plot_to_dynamic_size_file(str(img_0_path), dpi, file_0_size, height) cm_1.plot_to_dynamic_size_file(str(img_1_path), dpi, file_1_size, height) assert os.path.isfile(img_0_path) assert os.path.isfile(img_1_path) helper.assert_image_size(expected_0_size, str(img_0_path)) helper.assert_image_size(expected_1_size, str(img_1_path)) os.remove(img_0_path) os.remove(img_1_path)
def test_different_dpis(self): dpi_list = [16, 32, 64, 128, 256, 512, 1024] regions = self._extract_test_binary_regions() cm = ColorMap(self.test_binary_src, regions) temp_dir = tempfile.gettempdir() for i, dpi in enumerate(dpi_list): img_src = self._get_image_src( temp_dir, 'color_map_test_file-' + str(dpi) + '.png') expected_size = (ColorMap.FIG_SIZE[0] * dpi, ColorMap.FIG_SIZE[1] * dpi) cm.plot_to_file(img_src, dpi) helper.assert_image_size(expected_size, img_src) os.remove(img_src)
def test_plot_to_file_color_map_plot(self): dpi = 100 temp_dir = tempfile.gettempdir() # temp_dir = self.test_file_dir img_path = os.path.join( temp_dir, 'CodescannerAnalysisDataTest-test_plot_to_file_color_map_plot.png') expected_size = (dpi * ColorMap.FIG_SIZE[0], dpi * ColorMap.FIG_SIZE[1]) cad = CodescannerAnalysisData(self.test_file) cad.plot_to_file(str(img_path), dpi, cad.COLOR_MAP) assert os.path.isfile(img_path) helper.assert_image_size(expected_size, str(img_path)) os.remove(img_path)
def test_plot_to_file(self): dpi = 100 temp_dir = tempfile.gettempdir() # temp_dir = self.test_file_dir img_path = os.path.join(temp_dir, 'CMT-tptf.png') expected_size = (int(dpi * ColorMap.FIG_SIZE[0]), int(dpi * ColorMap.FIG_SIZE[1])) regions = self._extract_test_binary_regions() cm = ColorMap(self.test_binary_src, regions) cm.plot_to_file(str(img_path), dpi) assert os.path.isfile(img_path) helper.assert_image_size(expected_size, str(img_path)) os.remove(img_path)
def test_plot_to_file_byte_plot(self): dpi = 100 temp_dir = tempfile.gettempdir() # temp_dir = self.test_file_dir img_path = os.path.join( temp_dir, 'CodescannerAnalysisDataTest-test_plot_to_file_byte_plot.png') expected_size = (dpi * BytePlot.FIG_SIZE[0], dpi * BytePlot.FIG_SIZE[1]) p_file = self.test_file cad = CodescannerAnalysisData(p_file) cad.plot_to_file(str(img_path), dpi, cad.BYTE_PLOT) assert os.path.isfile(img_path) helper.assert_image_size(expected_size, str(img_path)) os.remove(img_path)
def test_plot_to_file_byte_plot_big_file(self): dpi = 100 temp_dir = tempfile.gettempdir() # temp_dir = self.test_file_dir img_path = os.path.join( temp_dir, 'CodescannerAnalysisDataTest-test_plot_to_file_byte_plot_big_file.png' ) expected_size = (dpi * BytePlot.FIG_SIZE[0], dpi * BytePlot.FIG_SIZE[1]) big_file = os.path.join(temp_dir, "big.bin") helper.create_random_file(big_file, (10 * 1024 * 1024)) # 10 mb cad = CodescannerAnalysisData(big_file) cad.plot_to_file(str(img_path), dpi, cad.BYTE_PLOT) assert os.path.isfile(img_path) helper.assert_image_size(expected_size, str(img_path)) os.remove(big_file) os.remove(img_path)
def test_plot_to_dynamic_size_random_file(self): dpi = 72 file_0_size = 0x2000 file_1_size = 0x4000 file_2_size = os.path.getsize(self.test_binary_src) height = 1000 temp_dir = tempfile.gettempdir() # temp_dir = self.test_file_dir img_0_path = os.path.join(temp_dir, 'CMT-tptdsf-0.png') img_1_path = os.path.join(temp_dir, 'CMT-tptdsf-1.png') img_2_path = os.path.join(temp_dir, 'CMT-tptdsf-2.png') expected_0_size = (int(dpi * file_0_size / PlotBase.DEFAULT_DPI), int(dpi * height / PlotBase.DEFAULT_DPI)) expected_1_size = (int(dpi * file_1_size / PlotBase.DEFAULT_DPI), int(dpi * height / PlotBase.DEFAULT_DPI)) expected_2_size = (int(dpi * file_2_size / PlotBase.DEFAULT_DPI), int(dpi * height / PlotBase.DEFAULT_DPI)) bin_0_src = os.path.join(temp_dir, 'CMT-tptdsf-0.bin') bin_1_src = os.path.join(temp_dir, 'CMT-tptdsf-1.bin') bin_2_src = self.test_binary_src helper.create_random_file(bin_0_src, file_0_size) helper.create_random_file(bin_1_src, file_1_size) r_0 = helper.extract_regions(bin_0_src) r_1 = helper.extract_regions(bin_1_src) r_2 = helper.extract_regions(bin_2_src) cm_0 = ColorMap(bin_0_src, r_0) cm_1 = ColorMap(bin_1_src, r_1) cm_2 = ColorMap(bin_2_src, r_2) cm_0.plot_to_dynamic_size_file(str(img_0_path), dpi, file_0_size, height) cm_1.plot_to_dynamic_size_file(str(img_1_path), dpi, file_1_size, height) cm_2.plot_to_dynamic_size_file(str(img_2_path), dpi, file_2_size, height) assert os.path.isfile(img_0_path) assert os.path.isfile(img_1_path) assert os.path.isfile(img_2_path) helper.assert_image_size(expected_0_size, str(img_0_path)) helper.assert_image_size(expected_1_size, str(img_1_path)) helper.assert_image_size(expected_2_size, str(img_2_path)) os.remove(img_0_path) os.remove(img_1_path) os.remove(img_2_path) os.remove(bin_0_src) os.remove(bin_1_src)