Carsten Schulte

118 papers A 8B 8C 2Journal 23Unranked 66
YearRankTypeTitle / Venue / Authors
2026 J jnl
CoRR
Lutz Terfloth, Heike M. Buhl, Vivien Lohmer, Michael Erol Schaffer, Friederike Kern, Carsten Schulte
2025 conf
ISSEP
Michael Lenke, Nils Oliver Klowait, Lea Biere, Carsten Schulte
2025 C conf
EDUCON
Michael Lenke, Carsten Schulte
2025 conf
Koli Calling
Sören Sparmann, Rukiye Altin, Andreas Mühling, Carsten Schulte
2024 J jnl
Informatics Educ.
Felix Winkelnkemper, Lukas Höper, Carsten Schulte
2024 ch.
Wirksamer Informatikunterricht
Carsten Schulte
2024 J jnl
Informatics Educ.
Lukas Höper, Carsten Schulte
2024 J jnl
CoRR
Michael Erol Schaffer, Lutz Terfloth, Carsten Schulte, Heike M. Buhl
2024 B conf
ETRA
Sven Hüsing, Sören Sparmann, Carsten Schulte, Mario Bolte
2024 conf
ICER (1)
Lukas Höper, Carsten Schulte, Andreas Mühling
2024 conf
Koli Calling
Lukas Höper, Carsten Schulte
2024 conf
xAI (Late-breaking Work, Demos, Doctoral Consortium)
Michael Erol Schaffer, Lutz Terfloth, Carsten Schulte, Heike M. Buhl
2024 conf
ITiCSE (1)
Lukas Höper, Carsten Schulte, Andreas Mühling
2024 conf
SIGCSE (1)
Sven Hüsing, Carsten Schulte, Sören Sparmann, Mario Bolte
2024 conf
ITiCSE (2)
Carsten Schulte, Sue Sentance, Sören Sparmann, Rukiye Altin, Mor Friebroon Yesharim, Martina Landman, Michael T. Rücker, Spruha Satavlekar, Angela A. Siegel, Matti Tedre, Laura Tubino, Henriikka Vartiainen, J. Ángel Velázquez-Iturbide, Jane Waite, Zihan Wu
2024 ch.
Künstliche Intelligenz für Lehrkräfte
Lukas Höper, Carsten Schulte, Christoph Benzmüller
2024 conf
ITiCSE-WGR
Carsten Schulte, Sue Sentance, Sören Sparmann, Rukiye Altin, Mor Friebroon Yesharim, Martina Landman, Michael T. Rücker, Spruha Satavlekar, Angela A. Siegel, Matti Tedre, Laura Tubino, Henriikka Vartiainen, J. Ángel Velázquez-Iturbide, Jane Waite, Zihan Wu
2024 J jnl
Cogn. Syst. Res.
Helen Beierling, Phillip Richter, Mara Brandt, Lutz Terfloth, Carsten Schulte, Heiko Wersing, Anna-Lisa Vollmer
2023 conf
xAI (3)
Lutz Terfloth, Michael Erol Schaffer, Heike M. Buhl, Carsten Schulte
2023 J jnl
CoRR
Lutz Terfloth, Michael Erol Schaffer, Heike M. Buhl, Carsten Schulte
2023 B conf
ETRA
Sören Sparmann, Carsten Schulte
2023 conf
GI-Jahrestagung
Yannik Fleischer, Sven Hülsing, Rolf Biehler, Lukas Höper, Susanne Podworny, Carsten Schulte
2023 J jnl
ACM Trans. Comput. Educ.
Gregor Große-Bölting, Dietrich Gerstenberger, Lara Gildehaus, Andreas Mühling, Carsten Schulte
2023 conf
Koli Calling
Sören Sparmann, Sven Hüsing, Carsten Schulte
2023 conf
Koli Calling
Felix Winkelnkemper, Carsten Schulte
2023 J jnl
CoRR
Helen Beierling, Phillip Richter, Mara Brandt, Lutz Terfloth, Carsten Schulte, Heiko Wersing, Anna-Lisa Vollmer
2022 conf
DeLFI Workshops
Birte Heinemann, Katja Eilerts, Tobias Huhmann, Carsten Schulte
2021 conf
INFOS
Susanne Podworny, Lukas Höper, Yannik Fleischer, Sven Hüsing, Carsten Schulte
2021 conf
GI-Jahrestagung
Lukas Höper, Carsten Schulte
2021 conf
INFOS
Lukas Höper, Carsten Schulte
2021 J jnl
IEEE Trans. Cogn. Dev. Syst.
Katharina J. Rohlfing, Philipp Cimiano, Ingrid Scharlau, Tobias Matzner, Heike M. Buhl, Hendrik Buschmeier, Elena Esposito, Angela Grimminger, Barbara Hammer, Reinhold Häb-Umbach, Ilona Horwath, Eyke Hüllermeier, Friederike Kern, Stefan Kopp, Kirsten Thommes, Axel-Cyrille Ngonga Ngomo, Carsten Schulte, Henning Wachsmuth, Petra Wagner, Britta Wrede
2021 ed.
ITiCSE
Carsten Schulte, Brett A. Becker, Monica Divitini, Erik Barendsen
2021 ed.
ITiCSE (2)
Carsten Schulte, Brett A. Becker, Monica Divitini, Erik Barendsen
2021 J jnl
ACM SIGCSE Bull.
Carsten Schulte, Brett A. Becker
2021 J jnl
ACM SIGCSE Bull.
Carsten Schulte, Brett A. Becker
2021 A conf
ICER
Gregor Große-Bölting, Dietrich Gerstenberger, Lara Gildehaus, Andreas Mühling, Carsten Schulte
2021 J jnl
LOG IN
Alexander Best, Martin Brämer, Volker Frederking, Katharina Geldreich, Ilka Goetz, Henry Herper, Ludger Humbert, Ulrich Kortenkamp, Günter Krauthausen, Silke Ladel, Carsten Schulte
2021 J jnl
LOG IN
Lukas Höper, Sven Hüsing, Hülya Malatyali, Carsten Schulte, Lea Budde
2021 conf
Koli Calling
Susanne Podworny, Yannik Fleischer, Sven Hüsing, Rolf Biehler, Daniel Frischemeier, Lukas Höper, Carsten Schulte
2021 conf
INFOS
Lukas Höper, Susanne Podworny, Sven Hüsing, Carsten Schulte, Yannik Fleischer, Rolf Biehler, Daniel Frischemeier, Hülya Malatyali
2020 conf
Koli Calling
Lutz Terfloth, Lea Budde, Carsten Schulte
2020 ch.
Encyclopedia of Education and Information Technologies
Johannes Magenheim, Carsten Schulte
2019 conf
Koli Calling
Andreas Mühling, Carsten Schulte, Jens Bennedsen, Lea Budde, Gregor Große-Bölting
2019 conf
INFOS
Ann-Katrin Schmidt, Carsten Schulte
2019 conf
WiPSCE
Simone Opel, Michael Schlichtig, Carsten Schulte
2019 conf
INFOS
Florian Kapp, Carsten Schulte
2019 conf
INFOS
Simone Opel, Michael Schlichtig, Carsten Schulte, Rolf Biehler, Daniel Frischemeier, Susanne Podworny, Thomas Wassong
2019 conf
ITiCSE-WGR
Cruz Izu, Carsten Schulte, Ashish Aggarwal, Quintin I. Cutts, Rodrigo Duran, Mirela Gutica, Birte Heinemann, Eileen T. Kraemer, Violetta Lonati, Claudio Mirolo, Renske Weeda
2019 conf
INFOS
Michael Schlichtig, Simone Opel, Carsten Schulte, Rolf Biehler, Daniel Frischemeier, Susanne Podworny, Thomas Wassong
2019 B conf
ITiCSE
Cruz Izu, Carsten Schulte, Ashish Aggarwal, Quintin I. Cutts, Rodrigo Duran, Mirela Gutica, Birte Heinemann, Eileen T. Kraemer, Violetta Lonati, Claudio Mirolo, Renske Weeda
2019 conf
INFOS
Kathrin Müller, Carsten Schulte, Johannes Magenheim
2018 conf
Koli Calling
Carsten Schulte, Lea Budde
2018 conf
WiPSCE
Kathrin Müller, Carsten Schulte
2018 J jnl
LOG IN
Johannes Magenheim, Carsten Schulte, Ulrik Schroeder, Ludger Humbert, Kathrin Müller, Nadine Bergner, Martin Fricke
2018 conf
Koli Calling
Birte Heinemann, Simone Opel, Lea Budde, Carsten Schulte, Daniel Frischemeier, Rolf Biehler, Susanne Podworny, Thomas Wassong
2018 conf
ISSEP
Johannes Magenheim, Kathrin Müller, Carsten Schulte, Nadine Bergner, Kathrin Haselmeier, Ludger Humbert, Dorothee Müller, Ulrik Schroeder
2018 conf
Koli Calling
Roman Bednarik, Carsten Schulte, Lea Budde, Birte Heinemann, Hana Vrzakova
2018 ed.
EMIP@ETRA
Roman Bednarik, Carsten Schulte
2018 conf
WiPSCE
Carsten Schulte, Jessica Krüger, Andreas Gödecke, Ann-Katrin Schmidt
2017 conf
WiPSCE
Lea Budde, Birte Heinemann, Carsten Schulte
2017 conf
INFOS
Kathrin Müller, Carsten Schulte
2017 C conf
EDUCON
Carsten Schulte, Johannes Magenheim, Kathrin Müller, Lea Budde
2017 conf
INFOS
Nadine Bergner, Hilde Köster, Johannes Magenheim, Kathrin Müller, Ralf Romeike, Ulrik Schroeder, Carsten Schulte
2015 A conf
ICPC
Teresa Busjahn, Roman Bednarik, Andrew Begel, Martha E. Crosby, James H. Paterson, Carsten Schulte, Bonita Sharif, Sascha Tamm
2015 B ed.
ITiCS
Valentina Dagiene, Carsten Schulte, Tatjana Jevsikova
2014 conf
PPIG
Teresa Busjahn, Carsten Schulte, Edna Kropp
2014 A conf
ICER
Teresa Busjahn, Carsten Schulte, Bonita Sharif, Simon, Andrew Begel, Michael Hansen, Roman Bednarik, Paul Orlov, Petri Ihantola, Galina Shchekotova, Maria Antropova
2014 ed.
WiPSCE
Carsten Schulte, Michael E. Caspersen, Judith Gal-Ezer
2014 B conf
ETRA
Teresa Busjahn, Roman Bednarik, Carsten Schulte
2013 conf
LaTiCE
Jens Bennedsen, Carsten Schulte
2013 conf
WiPSCE
Malte Buchholz, Mara Saeli, Carsten Schulte
2013 conf
WiPSCE
Carsten Schulte
2013 conf
Koli Calling
Teresa Busjahn, Carsten Schulte
2012 conf
Koli Calling
Carsten Schulte, Malte Hornung, Sue Sentance, Valentina Dagiene, Tatjana Jevsikova, Neena Thota, Anna Eckerdal, Anne-Kathrin Peters
2012 J jnl
Comput. Sci. Educ.
Carsten Schulte, Jarkko Suhonen
2012 conf
WiPSCE
Carsten Schulte
2011 conf
Koli Calling
Teresa Busjahn, Carsten Schulte, Andreas Busjahn
2011 conf
INFOS
Carsten Schulte
2011 conf
INFOS
Manuela Kalbitz, Hendrik Voss, Carsten Schulte
2011 conf
Koli Calling
Malte Hornung, Carsten Schulte
2010 ed.
Koli Calling
Carsten Schulte, Jarkko Suhonen
2010 conf
ITiCSE-WGR
Carsten Schulte, Tony Clear, Ahmad Taherkhani, Teresa Busjahn, James H. Paterson
2010 J jnl
ACM Trans. Comput. Educ.
Jens Bennedsen, Carsten Schulte
2010 B conf
ITiCSE
Albrecht Ehlert, Carsten Schulte
2010 ed.
DDI
Ira Diethelm, Christina Dörge, Claudia Hildebrandt, Carsten Schulte
2009 J jnl
ACM SIGCSE Bull.
Jürgen Börstler, Mark S. Hall, Marie Nordström, James H. Paterson, Kate Sanders, Carsten Schulte, Lynda Thomas
2009 B conf
ITiCSE
Torsten Brinda, Hermann Puhlmann, Carsten Schulte
2009 conf
INFOS
Carsten Schulte
2009 A conf
ICER
Albrecht Ehlert, Carsten Schulte
2009 conf
INFOS
Jochen Koubek, Carsten Schulte, Peter Schulze, Helmut Witten
2009 conf
DeLFI Workshops
Carsten Schulte, Robert Tolksdorf
2009 conf
INFOS
Albrecht Ehlert, Carsten Schulte
2008 A conf
ICER
Carsten Schulte
2008 conf
DDI
Carsten Schulte, Christina Dörge
2008 conf
ISSEP
Carsten Schulte
2008 B conf
ITiCSE
Christina Dörge, Carsten Schulte
2007 A conf
ICER
Carsten Schulte, Maria Knobelsdorf
2007 conf
INFOS
Carsten Schulte, Maria Knobelsdorf
2007 conf
INFOS
Carsten Schulte
2006 ed.
DDI
Andreas Schwill, Carsten Schulte, Marco Thomas
2006 conf
PPIG
Jens Bennedsen, Carsten Schulte
2006 conf
HDI
Carsten Schulte, Marco Thomas
2006 J jnl
ACM SIGCSE Bull.
Raymond Lister, Anders Berglund, Tony Clear, Joe Bergin, Kathy Garvin-Doxas, Brian Hanks, Lewis E. Hitchner, Andrew Luxton-Reilly, Kate Sanders, Carsten Schulte, Jacqueline L. Whalley
2006 J jnl
Educ. Inf. Technol.
Johannes Magenheim, Carsten Schulte
2006 A conf
ICER
Carsten Schulte, Jens Bennedsen
2005 conf
INFOS
Torsten Brinda, Carsten Schulte
2005 conf
INFOS
Carsten Schulte, Johannes Magenheim
2005 A conf
ICER
Carsten Schulte, Johannes Magenheim
2004 conf
Informatics and Student Assessment
Carsten Schulte
2003
Carsten Schulte
2003 J jnl
Comput. Sci. Educ.
Carsten Schulte, Johannes Magenheim, Jörg Niere, Wilhelm Schäfer
2002 conf
DDI
Carsten Schulte, Ulrich Block
2002 conf
GI Jahrestagung
Carsten Schulte
2002 J jnl
Softwaretechnik-Trends
Carsten Schulte
2001 conf
INFOS
Carsten Schulte, Olaf Scheel
2001 J jnl
Informatica Didact.
Carsten Schulte
1999 conf
INFOS
Thorsten Hampel, Johannes Magenheim, Carsten Schulte
1999 J jnl
LOG IN
Carsten Schulte, Harald Selke, Carsten Huth
tests/integration/test_elf_extractors.py
← Index tests/integration/test_elf_extractors.py python
"""
Integration tests for ELF-specific extractors.
"""
import pytest
from unittest.mock import Mock, patch, MagicMock

pytestmark = [pytest.mark.integration, pytest.mark.elf]


# ============================================================================
# ELFFeaturesExtractor Tests
# ============================================================================

class TestELFFeaturesExtractor:
    """Tests for ELFFeaturesExtractor class."""

    def test_extract_valid_elf(self, elf_binary_path, mock_logger):
        """Test extracting features from valid ELF file."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor
        from redb.models.dataclasses import ELFFeatures

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            assert isinstance(result, ELFFeatures)

    def test_extract_header_data(self, elf_binary_path, mock_logger):
        """Test ELF header data extraction."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            # Check header fields
            assert isinstance(result.ei_class, int)
            assert isinstance(result.ei_data, int)
            assert isinstance(result.e_type, int)
            assert isinstance(result.e_machine, int)
            assert isinstance(result.e_entry, int)

    def test_extract_human_readable_strings(self, elf_binary_path, mock_logger):
        """Test human-readable string fields."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            assert result.ei_class_str in ['32-bit', '64-bit', 'unknown']
            assert result.ei_data_str in ['Little-endian', 'Big-endian', 'unknown']
            assert result.e_type_str is not None
            assert result.e_machine_str is not None

    def test_extract_security_properties(self, elf_binary_path, mock_logger):
        """Test security property extraction."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            # Security flags should be 0 or 1
            assert result.is_pie in [0, 1]
            assert result.has_canary in [0, 1]
            assert result.has_nx in [0, 1]
            assert result.has_relro in [0, 1]
            assert result.has_fortify in [0, 1]

    def test_extract_counts(self, elf_binary_path, mock_logger):
        """Test section/segment/symbol counts."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            assert result.number_of_segments >= 0
            assert result.number_of_sections >= 0
            assert result.number_of_symbols >= 0
            assert result.number_of_dynamic_symbols >= 0
            assert result.number_of_relocations >= 0
            assert result.number_of_dependencies >= 0

    def test_extract_build_info(self, elf_binary_path, mock_logger):
        """Test build information extraction."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            # Build ID may or may not be present
            if result.build_id is not None:
                assert isinstance(result.build_id, str)
            assert result.gnu_hash_present in [0, 1]
            assert result.has_debug_info in [0, 1]

    def test_extract_invalid_elf(self, pe_binary_path, mock_logger):
        """Test extraction with non-ELF file."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(pe_binary_path, mock_logger)

            result = extractor.extract()

            # Should return None for invalid ELF
            assert result is None


# ============================================================================
# ELFSectionExtractor Tests
# ============================================================================

class TestELFSectionExtractor:
    """Tests for ELFSectionExtractor class."""

    def test_extract_sections(self, elf_binary_path, mock_logger):
        """Test section extraction."""
        from redb.extractors.elf_extractors.elf_sections import ELFSectionExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSectionExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            assert isinstance(result, list)
            assert len(result) > 0

    def test_section_properties(self, elf_binary_path, mock_logger):
        """Test section property extraction."""
        from redb.extractors.elf_extractors.elf_sections import ELFSectionExtractor
        from redb.models.dataclasses import ELFSection

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSectionExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None and len(result) > 0:
                section = result[0]
                assert isinstance(section, ELFSection)
                assert section.section_name is not None
                assert isinstance(section.section_type, int)
                assert isinstance(section.section_flags, int)
                assert section.section_entropy >= 0

    def test_section_hashes(self, elf_binary_path, mock_logger):
        """Test section hash computation."""
        from redb.extractors.elf_extractors.elf_sections import ELFSectionExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSectionExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None and len(result) > 0:
                for section in result:
                    if section.section_sha256:
                        assert len(section.section_sha256) == 64
                    if section.section_md5:
                        assert len(section.section_md5) == 32


# ============================================================================
# ELFSegmentExtractor Tests
# ============================================================================

class TestELFSegmentExtractor:
    """Tests for ELFSegmentExtractor class."""

    def test_extract_segments(self, elf_binary_path, mock_logger):
        """Test segment extraction."""
        from redb.extractors.elf_extractors.elf_segments import ELFSegmentExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSegmentExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            assert isinstance(result, list)

    def test_segment_properties(self, elf_binary_path, mock_logger):
        """Test segment property extraction."""
        from redb.extractors.elf_extractors.elf_segments import ELFSegmentExtractor
        from redb.models.dataclasses import ELFSegment

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSegmentExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None and len(result) > 0:
                segment = result[0]
                assert isinstance(segment, ELFSegment)
                assert isinstance(segment.segment_type, int)
                assert isinstance(segment.segment_flags, int)


# ============================================================================
# ELFSymbolExtractor Tests
# ============================================================================

class TestELFSymbolExtractor:
    """Tests for ELFSymbolExtractor class."""

    def test_extract_symbols(self, elf_binary_path, mock_logger):
        """Test symbol extraction."""
        from redb.extractors.elf_extractors.elf_symbols import ELFSymbolExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSymbolExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            # May be None if stripped
            if result is not None:
                assert isinstance(result, list)

    def test_symbol_properties(self, elf_binary_path, mock_logger):
        """Test symbol property extraction."""
        from redb.extractors.elf_extractors.elf_symbols import ELFSymbolExtractor
        from redb.models.dataclasses import ELFSymbol

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSymbolExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None and len(result) > 0:
                symbol = result[0]
                assert isinstance(symbol, ELFSymbol)
                assert symbol.symbol_name is not None
                assert isinstance(symbol.symbol_type, int)
                assert isinstance(symbol.symbol_bind, int)


# ============================================================================
# ELFImportExtractor Tests
# ============================================================================

class TestELFImportExtractor:
    """Tests for ELFImportExtractor class."""

    def test_extract_imports(self, elf_binary_path, mock_logger):
        """Test import extraction."""
        from redb.extractors.elf_extractors.elf_imports import ELFImportExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFImportExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            # May be None if no imports
            if result is not None:
                assert hasattr(result, 'elf_imports_total')

    def test_import_functions(self, elf_binary_path, mock_logger):
        """Test import function extraction."""
        from redb.extractors.elf_extractors.elf_imports import ELFImportExtractor
        from redb.models.dataclasses import ELFImport

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFImportExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None:
                assert isinstance(result, ELFImport)
                assert isinstance(result.elf_imports_total, int)


# ============================================================================
# ELFExportExtractor Tests
# ============================================================================

class TestELFExportExtractor:
    """Tests for ELFExportExtractor class."""

    def test_extract_exports(self, elf_binary_path, mock_logger):
        """Test export extraction."""
        from redb.extractors.elf_extractors.elf_exports import ELFExportExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFExportExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            # May be None if no exports
            if result is not None:
                assert hasattr(result, 'elf_exports_total')

    def test_export_functions(self, elf_binary_path, mock_logger):
        """Test export function extraction."""
        from redb.extractors.elf_extractors.elf_exports import ELFExportExtractor
        from redb.models.dataclasses import ELFExport

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFExportExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None:
                assert isinstance(result, ELFExport)


# ============================================================================
# ELFDependencyExtractor Tests
# ============================================================================

class TestELFDependencyExtractor:
    """Tests for ELFDependencyExtractor class."""

    def test_extract_dependencies(self, elf_binary_path, mock_logger):
        """Test dependency extraction."""
        from redb.extractors.elf_extractors.elf_dependencies import ELFDependencyExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFDependencyExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            # May be None if no dependencies
            if result is not None:
                assert isinstance(result, list)

    def test_dependency_properties(self, elf_binary_path, mock_logger):
        """Test dependency property extraction."""
        from redb.extractors.elf_extractors.elf_dependencies import ELFDependencyExtractor
        from redb.models.dataclasses import ELFDependency

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFDependencyExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None and len(result) > 0:
                dep = result[0]
                assert isinstance(dep, ELFDependency)
                assert dep.dependency_name is not None


# ============================================================================
# ELFRelocationExtractor Tests
# ============================================================================

class TestELFRelocationExtractor:
    """Tests for ELFRelocationExtractor class."""

    def test_extract_relocations(self, elf_binary_path, mock_logger):
        """Test relocation extraction."""
        from redb.extractors.elf_extractors.elf_relocations import ELFRelocationExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFRelocationExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            # May be None if no relocations
            if result is not None:
                assert isinstance(result, list)

    def test_relocation_properties(self, elf_binary_path, mock_logger):
        """Test relocation property extraction."""
        from redb.extractors.elf_extractors.elf_relocations import ELFRelocationExtractor
        from redb.models.dataclasses import ELFRelocation

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFRelocationExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None and len(result) > 0:
                reloc = result[0]
                assert isinstance(reloc, ELFRelocation)
                assert isinstance(reloc.relocation_offset, int)
                assert isinstance(reloc.relocation_type, int)


# ============================================================================
# ELFNotesExtractor Tests
# ============================================================================

class TestELFNotesExtractor:
    """Tests for ELFNotesExtractor class."""

    def test_extract_notes(self, elf_binary_path, mock_logger):
        """Test notes extraction."""
        from redb.extractors.elf_extractors.elf_notes import ELFNotesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFNotesExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            # May be None if no notes
            if result is not None:
                assert isinstance(result, list)

    def test_note_properties(self, elf_binary_path, mock_logger):
        """Test note property extraction."""
        from redb.extractors.elf_extractors.elf_notes import ELFNotesExtractor
        from redb.models.dataclasses import ELFNote

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFNotesExtractor(elf_binary_path, mock_logger)

            result = extractor.extract()

            if result is not None and len(result) > 0:
                note = result[0]
                assert isinstance(note, ELFNote)
                assert note.note_name is not None
                assert isinstance(note.note_type, int)


# ============================================================================
# Integration Tests
# ============================================================================

class TestELFExtractorIntegration:
    """Integration tests for ELF extractors."""

    def test_all_extractors_valid_elf(self, elf_binary_path, mock_logger):
        """Test all ELF extractors with valid ELF file."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor
        from redb.extractors.elf_extractors.elf_sections import ELFSectionExtractor
        from redb.extractors.elf_extractors.elf_segments import ELFSegmentExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            features_ext = ELFFeaturesExtractor(elf_binary_path, mock_logger)
            sections_ext = ELFSectionExtractor(elf_binary_path, mock_logger)
            segments_ext = ELFSegmentExtractor(elf_binary_path, mock_logger)

            features_result = features_ext.extract()
            sections_result = sections_ext.extract()
            segments_result = segments_ext.extract()

            # All should extract something
            assert features_result is not None
            assert sections_result is not None
            assert segments_result is not None

    def test_hash_consistency_across_extractors(self, elf_binary_path, mock_logger):
        """Test that hashes are consistent across all extractors."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor
        from redb.extractors.elf_extractors.elf_sections import ELFSectionExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            features_ext = ELFFeaturesExtractor(elf_binary_path, mock_logger)
            sections_ext = ELFSectionExtractor(elf_binary_path, mock_logger)

            # Hashes should be the same
            assert features_ext.sha256 == sections_ext.sha256
            assert features_ext.md5 == sections_ext.md5
            assert features_ext.sha1 == sections_ext.sha1

    def test_clickhouse_tables_unique(self, elf_binary_path, mock_logger):
        """Test that each extractor has a unique ClickHouse table."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor
        from redb.extractors.elf_extractors.elf_sections import ELFSectionExtractor
        from redb.extractors.elf_extractors.elf_segments import ELFSegmentExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            features_ext = ELFFeaturesExtractor(elf_binary_path, mock_logger)
            sections_ext = ELFSectionExtractor(elf_binary_path, mock_logger)
            segments_ext = ELFSegmentExtractor(elf_binary_path, mock_logger)

            tables = {
                features_ext.get_clickhouse_table(),
                sections_ext.get_clickhouse_table(),
                segments_ext.get_clickhouse_table(),
            }

            # All tables should be unique
            assert len(tables) == 3


# ============================================================================
# Advanced Binary Tests
# ============================================================================

class TestELFAdvancedBinary:
    """Tests using the hello_advanced binary."""

    def test_advanced_features_extraction(self, elf_advanced_binary_path, mock_logger):
        """Test feature extraction from advanced ELF binary."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(elf_advanced_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            assert result.number_of_sections > 0

    def test_advanced_sections_extraction(self, elf_advanced_binary_path, mock_logger):
        """Test section extraction from advanced ELF binary."""
        from redb.extractors.elf_extractors.elf_sections import ELFSectionExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSectionExtractor(elf_advanced_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            assert len(result) > 0

            # Check for common ELF sections
            section_names = [s.section_name for s in result]
            # Most ELF files have .text section
            assert any('.text' in name for name in section_names)

    def test_advanced_segments_extraction(self, elf_advanced_binary_path, mock_logger):
        """Test segment extraction from advanced ELF binary."""
        from redb.extractors.elf_extractors.elf_segments import ELFSegmentExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSegmentExtractor(elf_advanced_binary_path, mock_logger)

            result = extractor.extract()

            assert result is not None
            assert len(result) > 0


# ============================================================================
# Export Data Tests
# ============================================================================

class TestELFExtractorExportData:
    """Tests for export data preparation."""

    def test_features_prepare_export_clickhouse(self, elf_binary_path, mock_logger):
        """Test ClickHouse export preparation for features."""
        from redb.extractors.elf_extractors.elf_features import ELFFeaturesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFFeaturesExtractor(elf_binary_path, mock_logger)
            extractor.extract()

            result = extractor.prepare_export_data("ClickHouseExporter")

            assert result is not None
            data, column_names, column_type_names = result

            assert 'sha256' in column_names
            assert 'ei_class' in column_names
            assert 'e_machine' in column_names
            assert 'is_pie' in column_names

    def test_sections_prepare_export_clickhouse(self, elf_binary_path, mock_logger):
        """Test ClickHouse export preparation for sections."""
        from redb.extractors.elf_extractors.elf_sections import ELFSectionExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSectionExtractor(elf_binary_path, mock_logger)
            extractor.extract()

            result = extractor.prepare_export_data("ClickHouseExporter")

            if result is not None:
                data, column_names, column_type_names = result
                assert 'section_name' in column_names
                assert 'section_entropy' in column_names

    def test_segments_prepare_export_clickhouse(self, elf_binary_path, mock_logger):
        """Test ClickHouse export preparation for segments."""
        from redb.extractors.elf_extractors.elf_segments import ELFSegmentExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = ELFSegmentExtractor(elf_binary_path, mock_logger)
            extractor.extract()

            result = extractor.prepare_export_data("ClickHouseExporter")

            if result is not None:
                data, column_names, column_type_names = result
                assert 'segment_type' in column_names