Skip to content

Commit

Permalink
Log a message when a dissector invokes the untested callback
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecLad committed Jul 11, 2016
1 parent a5be357 commit abd89a5
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
This file is part of Octetoscope.
Copyright (C) 2016 Octetoscope contributors (see /AUTHORS.txt)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package ru.corrigendum.octetoscope.abstractinfra

trait Introspector {
def obtainCaller(): StackTraceElement
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of Octetoscope.
Copyright (C) 2013-2015 Octetoscope contributors (see /AUTHORS.txt)
Copyright (C) 2013-2016 Octetoscope contributors (see /AUTHORS.txt)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -21,7 +21,7 @@ package ru.corrigendum.octetoscope.application
import ru.corrigendum.octetoscope.abstractui.UIStrings
import ru.corrigendum.octetoscope.core.{getDetector, getDissectorDriver}
import ru.corrigendum.octetoscope.dissectors.magicMap
import ru.corrigendum.octetoscope.infra.{DefaultBinaryReader, DefaultClock, MessageLocalizer}
import ru.corrigendum.octetoscope.infra.{DefaultBinaryReader, DefaultClock, DefaultIntrospector, MessageLocalizer}
import ru.corrigendum.octetoscope.presentation.{DialogBoxerImpl, LoggerImpl, MainPresenter, PresentationStrings}
import ru.corrigendum.octetoscope.swingui.SwingApplication

Expand All @@ -45,6 +45,7 @@ object Octetoscope extends App {
new LoggerImpl(DefaultClock, view.logView),
DefaultBinaryReader,
DefaultClock,
DefaultIntrospector,
getDissectorDriver(getDetector(magicMap))
))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
This file is part of Octetoscope.
Copyright (C) 2016 Octetoscope contributors (see /AUTHORS.txt)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package ru.corrigendum.octetoscope.infra

import ru.corrigendum.octetoscope.abstractinfra.Introspector

/**
* Created by dpb on 18.01.2016.
*/
object DefaultIntrospector extends Introspector {
override def obtainCaller(): StackTraceElement = new Throwable().getStackTrace()(2)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package ru.corrigendum.octetoscope.presentation

import java.io.IOException

import ru.corrigendum.octetoscope.abstractinfra.{BinaryReader, Clock}
import ru.corrigendum.octetoscope.abstractinfra.{BinaryReader, Clock, Introspector}
import ru.corrigendum.octetoscope.abstractui.MainView
import ru.corrigendum.octetoscope.abstractui.MainView._
import ru.corrigendum.octetoscope.core._
Expand All @@ -35,6 +35,7 @@ object MainPresenter {
logger: Logger,
binaryReader: BinaryReader,
clock: Clock,
introspector: Introspector,
dissectorDriver: DissectorDriver): Unit = {
var numTabs = 0
var currentTabHandler: Option[TabHandler] = None
Expand Down Expand Up @@ -80,7 +81,11 @@ object MainPresenter {
logger.log(strings.logEntryDissectingFile(path.toString))
clock.timeExecution {() =>
val blob = binaryReader.readWhole(path)
(blob, dissectorDriver(blob, DissectionContext.ignoreUntested))
(blob, dissectorDriver(blob, () => {
val ste = introspector.obtainCaller()
logger.log(strings.logEntryUntested(
ste.getClassName, ste.getMethodName, ste.getFileName, ste.getLineNumber))
}))
}
} catch {
case e: Exception =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of Octetoscope.
Copyright (C) 2013-2015 Octetoscope contributors (see /AUTHORS.txt)
Copyright (C) 2013-2016 Octetoscope contributors (see /AUTHORS.txt)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -47,6 +47,9 @@ trait PresentationStrings {
@Translation(format = "successfully dissected file \"{0}\"")
def logEntrySuccessfullyDissectedFile(path: String): String

@Translation(format = "untested code path hit in {0}.{1} ({2}:{3})")
def logEntryUntested(className: String, methodName: String, fileName: String, lineNumber: Int): String

// Miscellaneous UI elements
@Translation(format = "This is {0} version {1}.")
def aboutText(appName: String, version: String): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ import ru.corrigendum.octetoscope.presentation.tools.{DisplayTreeNodeData, FakeM

class MainPresenterSuite extends path.FunSpec {
describe("A MainPresenter") {
val strings: PresentationStrings = FakeMessageLocalizer.localize(classOf[PresentationStrings])
val view = new MockMainView()
val boxer = new MockDialogBoxer()
val logger = new MockLogger()
val binaryReader = new MockBinaryReader()
val dissectorDriver = new MockDissectorDriver()
val strings: PresentationStrings = FakeMessageLocalizer.localize(classOf[PresentationStrings])

val clock = new MockClock(new Date(0), TimeZone.getTimeZone("UTC"))
val introspector = new MockIntrospector(MainPresenterSuite.FakeSTE)
val dissectorDriver = new MockDissectorDriver()

MainPresenter.attach(strings, "Blarf", view, boxer, logger, binaryReader, clock, dissectorDriver)
MainPresenter.attach(strings, "Blarf", view, boxer, logger, binaryReader, clock, introspector, dissectorDriver)

it("must put the window into the initial state") {
view mustBe 'visible
Expand Down Expand Up @@ -212,6 +212,27 @@ class MainPresenterSuite extends path.FunSpec {
}
}
}

describe("and the dissector invokes the untested callback") {
binaryReader.result = MainPresenterSuite.FakeBlob
dissectorDriver.result = MainPresenterSuite.FakePiece
dissectorDriver.invokeUntested = true
view.trigger(MainView.CommandEvent(MainView.Command.Open))

it("must generate a log message") {
view.tabs must have size 1 // sanity check

logger.entries mustBe Seq(
Seq(strings.logEntryDissectingFile(MainPresenterSuite.FakePath.toString)),
Seq(strings.logEntryUntested(MainPresenterSuite.FakeSTE.getClassName,
MainPresenterSuite.FakeSTE.getMethodName,
MainPresenterSuite.FakeSTE.getFileName,
MainPresenterSuite.FakeSTE.getLineNumber)),
Seq(strings.logEntrySuccessfullyDissectedFile(MainPresenterSuite.FakePath.toString),
strings.logEntryItTookSeconds(0))
)
}
}
}
}

Expand All @@ -237,4 +258,5 @@ object MainPresenterSuite {
SubPiece("eta", InfoSize(3, 4), Atom(InfoSize(), EmptyContents)), // zero-length between nibbles
SubPiece("theta", InfoSize(3, 6), Atom(InfoSize(), EmptyContents)) // zero-length in the middle of a right nibble
))
private val FakeSTE = new StackTraceElement("Foo", "bar", "Foo.scala", 12)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import ru.corrigendum.octetoscope.core.{DissectorDriver, PlainPiece, UntestedCal
class MockDissectorDriver extends DissectorDriver {
override def apply(path: Blob, untested: UntestedCallback): PlainPiece = {
exception.foreach(throw _)
if (invokeUntested) untested()
result
}

var result: PlainPiece = _
var exception: Option[Exception] = None
var invokeUntested: Boolean = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
This file is part of Octetoscope.
Copyright (C) 2016 Octetoscope contributors (see /AUTHORS.txt)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package ru.corrigendum.octetoscope.presentation.mocks

import ru.corrigendum.octetoscope.abstractinfra.Introspector

class MockIntrospector(val caller: StackTraceElement) extends Introspector {
override def obtainCaller(): StackTraceElement = caller
}

0 comments on commit abd89a5

Please sign in to comment.