How to say "had been [verbing]"?


In [this](https://japanese.stackexchange.com/a/19153/7508) excellent response
by @DariusJahandarie , he covered how to say "I have been [ _verbing_ ]" in
Japanese by using ている. He had given many examples of how would could
potentially translate ている or てい based on the context.

I'm wondering how you would differentiate between the following:

  * I was [ _verbing_ ]
  * I had been [ _verbing_ ]
  * I had [ _verbed_ ]

I will try a few sample sentences.

>   * 昨日は, テストのために **勉強している** とき, 彼女が来た。  
>  She came yesterday while _I was studying_ for my test.
>
>   * 昨夜はあなたが **電話した** とき, **勉強していた** 。  
>  _I was studying_ when _you had called_ last night.
>
>   * 私達がその本のことを初めて **話した** までに, 一週間私がそれをもう **読んでいた** 。  
>  By the time _we had_ first _talked_ about that book, _I had_ already _been
> reading_ it for a week.
>
>




I don't know if this answers your question but I would say them as:  

> 昨日、テスト勉強(を)しているときに、彼女が来た。  
>  Yesterday she came (to my place) while I was studying for a test.
>
> 昨夜、あなたが電話してきたとき、私は勉強していた。  
>  I was studying when you called me last night.
>
> 私達がその本のことを初めて話したときには、もう私は一週間それを読んでいた。  
>  By the time we first talked about that book, I had already been reading it
> for a week.

